質問

The following script works, but chrome says that there is an error..
What should I do to solve this error?

function Do(){alert("test");}

new MutationObserver(Do).observe(document.body,{childList:true,subtree:true}); //works, but there's error.

The error message in chrome console is this;

Uncaught NotFoundError: An attempt was made to reference a Node in a context where it does not exist. (anonymous function)

役に立ちましたか?

解決

The Node body has not been created when chrome executes the code. So you can change your code like this:

    window.onload=function(){
      function Do(){alert("test");};
      new MutationObserver(Do).observe(document.body,{childList:true,subtree:true});
    };

or do with jQuery:

    $(document).ready(function(){
    //your code
    });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top