Say some DOM node (like a <a>
tag) is bind with some events, like click to open a popup or anything. But I can't read the code which contains the binding stuff. How do I unbind them all? Is there any simple way/hack?
update again:
--
I checked the Elements > Event Listeners
with my Chrome and found that there is a click event handler on my a
, to make sure I am right, I tried the following steps:
First, I manually added a click handler from the console like this:
$a.click(function(){console.log(1)});
And I go back to the listeners tab, hit the refresh button, there is one more (now two handlers).
Then I use:
$a.off();
And I go back again, the one that I manually added is gone, remains only one handler (the one I want to git rid of)
And I used the replace-node way, and go back again, I found that the click handler is totally gone. That is what I want.
So, it's like $a.off()
is not working, even though it's pretty sure that the event is bind to the element itself, not its parent nodes.
--
update:
- I am using jQuery
- I tried
$.unbind()
and$.off()
, neither works - I used
$('#myEl').replaceWith($('#myEl').clone());
and this works fine. But it seems this way is not very perfect.