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

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -