Does jQuery.unbind () method work only with jQuery generated events?

I am trying to untie all event handlers for all elements inside a specific container. Like a div. But these events were not linked / logged using jQuery. Some of them are associated with the manual method using onclick="...." or using normal native JavaScript.

But when I do something like this

 $('#TheDivContainer').find('div,td,tr,tbody,table').unbind(); 

He does not work. This makes me think .unbind () only works if the events were originally jQuery related.

It's true? Is there any other way to undo all events from a group of elements?

Thanks!

+7
javascript jquery javascript-events
source share
3 answers

You're right. Like in the API :

Any handler that was attached with .bind () can be removed using .unbind ().

+7
source share

You can always do this:

 $('#TheDivContainer').find('div,td,tr,tbody,table') .unbind('click') .attr('onclick', ''); // edited to change null to '' 

etc .. for all relevant event types.

+3
source share

Unbind will only work with jQuery events generated, since all the methods that do this (addEventListener and attachEvent) require node, eventname, and as arguments. bind stores them for you.

By the way, LEMENES events of the DOM0 style ( .foo = function(...) can be removed by setting the same property to something like null .

+3
source share

All Articles