How do I find which JavaScript is changing an element's style?

前端 未结 5 472
攒了一身酷
攒了一身酷 2020-12-08 09:44

I have an element that\'s getting styles applied via JavaScript. I\'m not sure exactly where; is there a way to check Firebug to show where the \"element.style\" is actually

5条回答
  •  半阙折子戏
    2020-12-08 10:12

    If you're sure it's being set on the inline style and not as a consequence of a stylesheet rule, you can detect changes using the non-standard Mozilla watch() method:

    document.body.style.watch('color', function(name, v0, v1) {
        alert(name+': '+v0+'->'+v1);
    });
    document.body.style.color= 'red';
    

    You can put debugger; in the watcher function and look up the call stack in Firebug to see where the change was triggered.

提交回复
热议问题