Can jQuery selectors be used with DOM mutation observers?

后端 未结 4 1255
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 10:23

HTML5 includes a concept of \"mutation observers\" to monitor changes to the browser\'s DOM.

Your observer callback will be passed data which looks a lot like DOM tr

4条回答
  •  感动是毒
    2020-12-04 11:03

    I was working on a very similar problem for a Stack Exchange script I'm working on, and I needed to be able to monitor the DOM for changes. The jQuery docs didn't have anything helpful, but I did discover that the DOMNodeInserted event works in Chrome:

    document.addEventListener("DOMNodeInserted", function(event){
        var element = event.target;
    
        if (element.tagName == 'DIV') {
            if (element.id == 'seContainerInbox') {
                //alert($('#seContainerInbox').parent().get(0).tagName);
                trimStoredItems();
                $('#seTabInbox').click();
                //   var newCount = getNewCount();
                // if there are new inbox items, store them for later
                storeNewInboxItems();
                applyNewStyleToItems();
            }
        }
    });
    

    I'm not 100% sure if this works in Firefox as I haven't got that far yet in the development process. Hope this helps!

提交回复
热议问题