变异观察者不适用于jquery?

时间:2017-01-20 04:33:50

标签: javascript jquery dom mutation-observers

我尝试选择facebook.com的每个Feed项,其userContentWrapper类,但我得到0作为长度。我的观察者下面有什么问题吗?

   var insertedNodes = [];
   var observer = new MutationObserver(function (mutations, observer) {

       mutations.forEach(function(mutation) {

        $(mutation).closest('.userContentWrapper').css({'background':'red'});

        console.log($(mutation).closest('.userContentWrapper')) // length 0

        })
   });

    // pass in the target node, as well as the observer options
    observer.observe($('[id^=topnews_main_stream_]').get(0), {childList: true, subtree:true});

0 个答案:

没有答案