Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect the code acting on an element in DevTools

Tags:

I have a web-page with the open Dev/F12 Tools (in Chrome).

When the page is resized, one of the observed div's style properties is modified certainly by some JavaScript code (chrome displays modified properties in purple):
enter image description here

Is there a way to know, what exactly JS code does it, track the JS source of the modification of a DOM element?

like image 586
serge Avatar asked Mar 07 '18 10:03

serge


People also ask

How do I see JavaScript code in Chrome?

Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.

How do I see console elements?

Apart from clicking on "More tools-> Developer Tools", we can also open the element box using the following options: Clicking the F12 key. Using keyboard shortcut, "Ctrl + Shift + i" or "Ctrl + Shift + c" on Windows Operating System. The same command works on Chrome OS and Linux.

What is Inspect Element console?

Learning how to inspect elements in a browser is beneficial, especially if you work in IT. Inspect Element lets visitors access and temporarily edit a website's front-end source code, including its HTML, CSS, JavaScript, and image files.


1 Answers

Yes, you can use Chrome's devtools DOM Breakpoints to do that:

  1. Locate the element in the Elements pane (you've done that)
  2. Right-click the element and choose Break on > attribute modifications (because changing an inline style involves modifying the style attribute's value)

When the modification occurs, the breakpoint will stop JavaScript execution at that point and show the relevant script in the Sources tab.

If you ever need at some point to see a list of our DOM breakpoints, they're in the DOM Breakpoints tab in the panel to the right of the Elements panel.

like image 157
T.J. Crowder Avatar answered Sep 20 '22 13:09

T.J. Crowder