AJ_H AJ_H - 1 year ago 62
CSS Question

Tracking Down JavaScript that Applies Inline Style on Page Load

I'm managing a DNN site and trying to find the source of a "width: 100%" inline style being applied to certain elements on my home page. There's a whole mess of JS libraries included in DNN that are difficult to manually parse through, but I've popped open Chrome Developer Tools and searched in the Sources tab for every JS file that loads on the page to see where "100%" is being used. No dice.

I'm aware of the Break on... > Attributes Modifications functionality. This was always cited as the solution for similar issues I found on SO:

How to track down javascript that is modifying the inline style of a div in the DOM?

Finding Javascript-Applied Inline Styles to Debug Javascript

How can I find out what script is setting my element's visibility to hidden?

Which JS added inline styles?

The problem is this that unlike debugging JavaScript in the Sources tab, the debug point on HTML elements in the Elements tab gets wiped when you refresh the webpage, and the script I'm trying to track down only runs once on page load and never again during runtime, so the breakpoint never gets hit.

Are there any other methods of identifying when or where the attributes on a specific element in the DOM change during page load? Or maybe tracking a specific attribute?

Answer Source
  1. Place a script tag with the debugger statement immediately after the element which gets its attribute changed:

  2. Reload the page with the inspector open
  3. Switch to the elements tab and add an attribute removal breakpoint to the element
  4. Resume script execution

DevTools will now highlight the code which changes the attribute.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download