Say I had a div#parent
and I append
and remove
elements to it using jquery. How would I be able to detect when such an event happens on the div#parent
element?
Advertisement
Answer
Use Mutation Observers as suggested by @Qantas in his answer
Following methods are deprecated
You can use DOMNodeInserted and DOMNodeRemoved
JavaScript
x
8
1
$("#parent").on('DOMNodeInserted', function(e) {
2
console.log(e.target, ' was inserted');
3
});
4
5
$("#parent").on('DOMNodeRemoved', function(e) {
6
console.log(e.target, ' was removed');
7
});
8