js dynamically monitor dom changes

Native js dynamically monitors dom changes and binds different processing logic according to different types

 

 

 

// Firefox和Chrome早期版本中带有前缀  
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver      // 选择目标节点   var target = document.querySelector('#some-id');       // 创建观察者对象   var observer = new MutationObserver(function(mutations) {     mutations.forEach(function(mutation) {       console.log(mutation.type);     });       });       // 配置观察选项:   var config = { attributes: true, childList: true, characterData: true }       // 传入目标节点和观察选项   observer.observe(target, config);       // 随后,你还可以停止观察   observer.disconnect();  

 

Browser support:

 

Copyright belongs to the author.
For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.
Original:  https://lcddjm.com/article/5a9fac195809d15ba1019710  ©  www.lcddjm.com

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325149260&siteId=291194637
Recommended