我尝试选择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});