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
Post a Comment