jQuery.bind(“remove”)

不打扰是莪最后的温柔 提交于 2019-12-12 16:16:08

问题


Is there a way have an event handler run when a dom element is removed? I have not seen this documented anywhere. It seems it mightt be possible since jQuery is able to remove data and events on element removal.


回答1:


Binding DOMNodeRemoved will allow for you to detect removal of nodes inside the bound element. Works in Firefox, Iron and Opera... but not IE.

jQuery

$("#detectchanges").bind("DOMNodeRemoved",function(){
  alert('Something inside of detectchanges was terminated.');
});

$("#clickme").click(function(){
  $("#deleteme").remove();
});

HTML

<div id="detectchanges">
  <div id="deleteme">Delete me</div>
</div>

<div id="clickme">Delete</div>

Here's an example.



来源:https://stackoverflow.com/questions/3432944/jquery-bindremove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!