我想调用某个功能时另一个脚本将div到body。
我试过了:
var dom_observer = new MutationObserver(function(mutation) {
console.log('function called');
});
var container = document.body;
console.log(container);
var config = { attributes: true, childList: true, characterData: true };
dom_observer.observe(container, config);
Run Code Online (Sandbox Code Playgroud)
我尝试将设置container为document.body(上面的示例)和document.querySelector('body')。在这两种情况下,都会console.log()显示,null并且出现以下错误:TypeError: Argument 1 of MutationObserver.observe is not an object.。div向中添加时未调用回调函数body。
我尝试将其设置为document.getElementsByTagName("body")[0]和document.documentElement.childNodes[1]。在这两种情况下,console.log()display undefined和callback函数仍然从未被调用。