Reputation: 967
I've been trying things like
$(':input').blur(doStuff());
and
$('*').bind('blur', doStuff());
but nothing seems to trigger correctly. What's the best way to do this?
Upvotes: 1
Views: 2984
Reputation: 318222
First of all, blur doesn't bubble, but jQuery sorta fixes that and makes it bubble, but you could still try focusout
instead as that is an event that actually does bubble.
Secondly, you're calling the callback function, not referencing it, it should be
$('*').on('focusout', doStuff);
Thirdly, this is a really bad idea, listening for an event that bubbles on all elements in the DOM, you should probably at least just listen on the top most level
$(document).on('focusout', doStuff);
and even that is not really a very good idea, it would be better to target the elements directly.
Upvotes: 6