jquery - How to prevent focusout when focusin fires on the same element? -



jquery - How to prevent focusout when focusin fires on the same element? -

i'm attaching .active class div wrapped around input , label.

my problem when element clicked within wrapped div, focusout fire, , causing slight flicker of styling.

$('body') .on('focusin', '.formlabel', function() { $(this).addclass('active'); }) .on('focusout', '.formlabel', function() { $('.formlabel').removeclass('active'); });

here's example: http://jsbin.com/mamacogimo/1/edit?html,js,output - click label , item dropdown. notice bluish background flickers.

is there anyway prevent flickering?

you can utilize timeout, so:

var timeout; $('body').on('focusin', '.formlabel', function() { $(this).addclass('active'); cleartimeout(timeout); }).on('focusout', '.formlabel', function(e) { timeout = settimeout(function() { $('.formlabel').removeclass('active'); }, 250); });

http://jsbin.com/dafubiweto/2/edit

jquery focusout focusin

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -