我希望在dom中插入一个节点时添加一个节点元素。
当我调用observe
方法时,出现错误:Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
我的代码:
var mutationObserver = new MutationObserver( function(mutations) {
mutations.forEach( function(mutation) {
console.log(mutation);
// here I'd like to insert my new node
});
});
var options = {
childList: true
};
var targetNode = document.querySelector('div.nav-bar');
console.log(targetNode); //null - and not null after dom ready
mutationObserver.observe(targetNode, options);