I have a div element with several elements inside it like buttons and so forth which have event handlers attached to them. I know its possible to go:
我有一个div元素,里面有几个元素,比如按钮等等,它们都有事件处理程序。我知道有可能:
$("#button1").off()
To remove the handler for a button but I would like to do something like this if possible:
要删除按钮的处理程序,但如果可能的话,我想做如下操作:
$("#div1").removeChildHandlers();
Is there a native function in JQuery to do this or would I have to loop them all the elements and remove 1 by 1?
在JQuery中是否有一个本机函数来做这个呢?或者我需要循环所有元素并移除1 * 1?
3 个解决方案
#1
31
jQuery will do the looping for you for just the direct children:
jQuery将为您做循环,只针对直接子程序:
$("#div1").children().off();
or if you want all descendants:
或者如果你想要所有的后代:
$("#div1").find("*").off();
#2
3
Does this help:
这是否帮助:
$("#div1").find('*').off();
#3
1
Try with
试着用
$("#div1 >* ").off();
Or:
或者:
$("#div1").find('button').off();
if you're talking about <button>
elements
如果你说的是
#1
31
jQuery will do the looping for you for just the direct children:
jQuery将为您做循环,只针对直接子程序:
$("#div1").children().off();
or if you want all descendants:
或者如果你想要所有的后代:
$("#div1").find("*").off();
#2
3
Does this help:
这是否帮助:
$("#div1").find('*').off();
#3
1
Try with
试着用
$("#div1 >* ").off();
Or:
或者:
$("#div1").find('button').off();
if you're talking about <button>
elements
如果你说的是