问题
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