How to focus div?

html, jquery

Solution

You have to set tabindex attribute:

http://jsfiddle.net/QAkGV/

<div id="focusedDiv" tabindex="-1"></div>

Or:

$("#focusedDiv").attr('tabindex',-1).focus(function () {
        ....
    });

For style, you could set outline CSS property too:

$("#focusedDiv").css('outline',0).attr('tabindex',-1).focus(function () {
        ....
    });

Problem

Please don't throw stones at me because i'm total newbie at js and jquery. is it possible to focus a div? i just wanted to process events when div is clicked OR is focused and when we click outside the div. Something like that: HTML: ``` <div id="focusedDiv"></div> ``` JS: ``` $("#focusedDiv").focus(function () { .... }); $("#focusedDiv").focusout(function () { .... }); ``` Thanks in advance!

Original source

Related problems