Good approch for see if something is removed from

2019-08-23 20:55发布

问题:

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/