Is it possible to write onFocus/lostFocus handler for a DIV using JS or jQuery?
I have a div and when the user clicks the div a function should be called. And when the user clicks something else (anything other than this div) another function should be called. So basically i need to have onFocus() and lostFocus() function calls associated with this DIV. Is it available in JavaScript or even in jQuery? Thanks. Here i created a Working demo of what you want http://jsfiddle.net/kPbfL/1/ You need to add tabindex attribute to div : Markup: <div id="mydiv" tabindex="-1"></div> Javascript $("#mydiv").focusin(function() { $("#mydiv").css("background","red"); }); $("#mydiv")