Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find what javascript changes the DOM?

I've been working with a ton of other's JS recently, and am starting to really hate trying to debug it. Even with Chrome's dev tools I can't track down a lot of the DOM changes that are taking place during page load.

Are there any tools that will show me what part of the DOM (say an added attribute) was done by what JS?

Thanks

like image 936
Ben Avatar asked Jun 29 '12 20:06

Ben


People also ask

How do you detect change in DOM?

We insert a new p element after 1 second 5 times. We pass in a callback into the MutationObserver constructor that runs when the DOM changes. Then we call observe on the element that we want to observe changes for. subtree set to true means that we watch for child element changes.

Can JavaScript modify DOM?

The HTML DOM allows JavaScript to change the content of HTML elements.

How do I find my DOM element?

The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.


2 Answers

In Chrome dev tools, you have the option of breaking execution when the DOM changes. enter image description here

Also a screenshot to illustrate Wolfram's answer (+1)

enter image description here

like image 50
Jay Avatar answered Sep 21 '22 04:09

Jay


A minor addition to Jayraj's answer: Breakpoints on DOM Mutation Events. Right click on any element and you can select Break on Subtree Modifications and Break on Attributes Modifications and Break on Node Removal.

This is also possible using Firebug: right click an element and you have some options to monitor it for changes.

like image 23
Wolfram Avatar answered Sep 18 '22 04:09

Wolfram