nkcmr
nkcmr

Reputation: 11010

Is it possible to blur input without firing the blur event?

I'm running into errors because an event binder in jQuery is attached to 'keyup' and 'blur'. But when I remove the input from the DOM that seems to fire the blur event, thus re-running the handler on a non-existent DOM input.

Upvotes: 3

Views: 1768

Answers (2)

jwatts1980
jwatts1980

Reputation: 7356

You can validate this in the handler when the event is fired

if (this && $(this).length > 0 ) { /*do stuff*/ }

Upvotes: 0

icktoofay
icktoofay

Reputation: 129001

If the event listener was added with jQuery, you could use unbind:

$(/* ... */).unbind('blur');

In newer versions of jQuery, off is preferred:

$(/* ... */).off('blur');

Upvotes: 1

Related Questions