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
You need to add tabindex attribute to div :
tabindex
div
$("#mydiv").focusin(function() { $("#mydiv").css("background", "red"); }); $("#mydiv").focusout(function() { $("#mydiv").css("background", "white"); });
#mydiv { width: 50px; height: 50px; border: 1px solid red; }