admin管理员组文章数量:1356092
Chrome's developer tools provides the option to break the javascript code execution when an element's attributes or DOM tree are modified. (Inspect an element > right-click on the element tag > "Break on…")
However, I would like to jump into the code when the innerHTML of an element is changed by JavaScript. Activating all the "break on" options won't do it, so I'd like to know if there is some way to do it.
Chrome's developer tools provides the option to break the javascript code execution when an element's attributes or DOM tree are modified. (Inspect an element > right-click on the element tag > "Break on…")
However, I would like to jump into the code when the innerHTML of an element is changed by JavaScript. Activating all the "break on" options won't do it, so I'd like to know if there is some way to do it.
4 Answers
Reset to default 3- Text node is a child node.
- To change a text, the browser remove the old text child node.
- Subtree Modifications is a flag. When this flag is on, you can listen
- Attribute modifications with subtree
- Node removal with subtree
So, You should check two. node removal and subtree modifications.
Also, you can use MutationObserver API directly.
Old events (DOMSubtreeModified
, DOMCharacterDataModified
, ...) are deprecated. mdn, google
I would suggest trying DOMSubtreeModified Event .
$("#elem").on("DOMCharacterDataModified", function(){
alert("Modified");
});
Fiddle
I found a trick to do that, first you can edit the dom html and append a html tag,
say <b>foo</b>
, then set a Subtree break on the dom. When the dom changes it will trigger the break.
As per Alexander's suggestion, you can use DOMSubtreeModified
:
$0.addEventListener('DOMSubtreeModified', function(){debugger;});
(Where $0 is an inspected element.)
However, as DOMSubtreeModified
is deprecated, I also want to throw an alternative out there. Unfortunately this only works when the inner HTML is changed by the actual innerHTML
property:
Object.defineProperty($0, 'innerHTML', {set:function(){debugger;}})
本文标签: javascriptBreak on quotinnerHTMLquot changes in ChromeStack Overflow
版权声明:本文标题:javascript - Break on "innerHTML" changes in Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744049009a2582072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论