I currently have the code:
$('.example').bind('DOMNodeInserted DOMNodeRemoved', function(event) {
....
});
Which works perfectly but it is not very efficient and has since deprecated. What is a better way to do this?
I have been looking into MutationObserver but this code does work?
It is giving the error "mutation.addedNodes
is not a function" I would also need the removedNodes
I realise.
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.className == 'example') {
....
}
});
});
});
observer.observe(document, {
childList: true,
subtree: true,
attributes: false,
characterData: false,
});