admin管理员组文章数量:1314571
I am trying to unbind all event handlers for all elements that are inside a particular container. Like a DIV. But those events have been bound/registered not using jQuery. Some are bound the manual way with onclick="...."
or using regular native JavaScript.
But when I do something like this
$('#TheDivContainer').find('div,td,tr,tbody,table').unbind();
It does not appear to work. Which leads me to believe that the .unbind()
only works if the events have been originally bound by jQuery.
Is that true? Is there another way of unbinding all events from a group of elements?
Thanks!
I am trying to unbind all event handlers for all elements that are inside a particular container. Like a DIV. But those events have been bound/registered not using jQuery. Some are bound the manual way with onclick="...."
or using regular native JavaScript.
But when I do something like this
$('#TheDivContainer').find('div,td,tr,tbody,table').unbind();
It does not appear to work. Which leads me to believe that the .unbind()
only works if the events have been originally bound by jQuery.
Is that true? Is there another way of unbinding all events from a group of elements?
Thanks!
Share Improve this question edited Dec 21, 2022 at 8:38 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 1, 2010 at 19:25 7wp7wp 12.7k20 gold badges79 silver badges107 bronze badges3 Answers
Reset to default 7You are right. As in the API:
Any handler that has been attached with .bind() can be removed with .unbind().
Unbind will only work on jQuery created events as all methods that does this (addEventListener, and attachEvent) requires the both the node, the eventname, and the handler as an argument. bind
takes care of storing these for you..
By the way, DOM0 style event listerens (.foo = function(...)
can only by removed by setting the same property to something else like null
.
You could always do this:
$('#TheDivContainer').find('div,td,tr,tbody,table')
.unbind('click')
.attr('onclick', ''); // edited to change null to ''
etc. for all appropriate event types.
本文标签: javascriptDoes the jQuery unbind() method only work on jQuery created eventsStack Overflow
版权声明:本文标题:javascript - Does the jQuery .unbind() method only work on jQuery created events? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741962976a2407389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论