javascript - How to hide an element by Id with mutation observer -


i've read https://hacks.mozilla.org/2012/05/dom-mutationobserver-reacting-to-dom-changes-without-killing-browser-performance/ still not sure how configure achieve objective.

there's element on page being generated code generator (so cannot prevent bevahiour). element has id "myid" , need hide once displays in browser. challenge how configure observer such code fires when element displayed.

i've inserted questions comments think need here kindly guide me if i've got wrong:

var target = document.queryselector('#myid');     var observer = new mutationobserver(function(mutations) {    mutations.foreach(function(mutation) {      // how detect when element on page next statement makes sense?      document.getelementbyid("myid").style.visibility = "hidden";         });      });     // change need make here?  var config = { attributes: true, childlist: true, characterdata: true };      observer.observe(target, config);     observer.disconnect();

why don't use css? way don't have worry when item created @ all, won't need script begin with.

#myid {   visibility: hidden; /*!important; if necessary*/ } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -