Kel
Kel

Reputation: 409

Removing event handlers of children

I am trying to unbind event handlers (click) from all a-tags, and somehow it is not working. Do you guys know why?

// Remove eventhandlers
    row.find('a').each(function(){
        $(this).unbind('click');
        alert($(this).attr("onClick"));
    });

It will always output the current onClick function.

Thanks

Upvotes: 2

Views: 1360

Answers (2)

filster
filster

Reputation: 21

$('a').unbind('click');

or

$('a').each(function() {
  return false;
});

Upvotes: 0

user113716
user113716

Reputation: 322502

jQuery's .unbind() only removes handlers assigned and maintained by jQuery. Your inline handlers are not affected.

If you want to remove an inline attribute, use removeAttr().

row.find('a').each(function(){
    $(this).removeAttr('onClick');
    alert($(this).attr("onClick"));
});

http://api.jquery.com/removeattr/

Upvotes: 4

Related Questions