Previously, you could connect to the jQuery domManip method to catch all the jQuery dom manipulations and see what elements were inserted there, etc., but the jQuery team closed this in jQuery 3.0+, since this is usually a bad solution to connect to jQuery methods like this way, and they did it, so the domManip internal method domManip no longer available outside jQuery core code.
The mutation events are also outdated, since earlier it was possible to do something like
$(document).on('DOMNodeInserted', function(e) { if ( $(e.target).hasClass('MyClass') ) {
this should be avoided, and today mutation observers should be used instead, which will work as follows
var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { console.log(mutation) if (mutation.addedNodes && mutation.addedNodes.length > 0) { // element added to DOM var hasClass = [].some.call(mutation.addedNodes, function(el) { return el.classList.contains('MyClass') }); if (hasClass) { // element has class `MyClass` console.log('element ".MyClass" added'); } } }); }); var config = { attributes: true, childList: true, characterData: true }; observer.observe(document.body, config);
adeneo May 02 '12 at 14:17 2012-05-02 14:17
source share