How to listen in on DOM changes that you make with chrome developer tool

倾然丶 夕夏残阳落幕 提交于 2019-12-10 04:04:49

问题


I need to make an application that can detect when I use chrome developer tool to update attributes on a webpage. E.g. if I bring up the developer tool, use the elements selector and change the font size of a specific element (see picture). I should be able to have a program running that is notified with what element was updated on the page, and what attributes was changed.

How could that be done?


回答1:


It sounds like a mutation observor job. Have a look at https://developer.mozilla.org/en/docs/Web/API/MutationObserver

Example http://jsfiddle.net/3y3rpfq5/1/

Sample code:

var target = document.querySelector('#some-id');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    console.log(mutation.type);
  });    
});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };

// pass in the target node, as well as the observer options
observer.observe(target, config);


来源:https://stackoverflow.com/questions/27187261/how-to-listen-in-on-dom-changes-that-you-make-with-chrome-developer-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!