javascript - jQuery alternative for document.activeElement -


what wanted figure out whenever user engaged input or textarea element , set variable flag true... , set flag false after user no longer engaged them (ie. they've clicked out of input/textarea elements).

i used jquery's docuemnt.ready function add onclick attribute body element , assign getactive() function.

the code getactive() function follows:

 function getactive() {   activeobj = document.activeelement;   var infocus = false;   if (activeobj.tagname == "input" || activeobj.tagname == "textarea")   {      infocus = true;   } } 

i'd keep project withing jquery framework, can't seem find way of accomplishing same logic above using jquery syntax.

you want focus , blur event handlers. example...

var infocus = false; $('input, textarea').focus(function() {   infocus = true; });  $('input, textarea').blur(function() {   infocus = false; }); 

i'm pretty sure comma input or textarea, idea if doesn't pan out


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -