Good approch for see if something is removed from the DOM with contenteditable

為{幸葍}努か 提交于 2019-12-12 00:39:06

问题


I have this little snippet.

​<div contenteditable="true">
 <img src="/img/logo.png">
</div>

I need to know when the image are removed, in the real world application its much much more inside the div.

One way I can complete this is by jQuery and look at the parent for the image. The parent disappers when its removed, but is that a good approch? Maybe it exist some event that is raised?

I have created this little example http://jsfiddle.net/V6sdA/


回答1:


.bind('DOMNodeInserted DOMNodeRemoved')

These are the events to check element is inserted or removed.

Bind these events on the parent element and call your function in the handler.

jsFiddle demo : http://jsfiddle.net/PgAJT/



来源:https://stackoverflow.com/questions/9699597/good-approch-for-see-if-something-is-removed-from-the-dom-with-contenteditable

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