The following code works on page load but it is never fires when I insert an element (div) to the DOM with jquery.append()
Is there any way to catch with MutationObserver when an element has been added?
here is my code
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer){
mutations.forEach(function(mutation) {
if($(mutation.target).length > 0){
if($(mutation.target).prop('tagName').toLowerCase() === 'img'){
console.log('IMG ADDED', $(mutation.target));
}
}
});
});
observer.observe(document,{subtree:true, attributes:true, characterData:true});
OK I figured it out... Thought I would post to save someone the headache..
I needed childList:true as well
observer.observe(document,{childList:true, subtree:true, attributes:true, characterData:true});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With