Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the origin source of an element.style? i.e. Which JS or jQ file is injecting it. I want to fix, not override

The styles in question are not hardcoded into the HTML or CSS. They're being dynamically added in through either a JS or jQ file. I run into this all the time. I always end up just reading through all of the files until I find it. Is there a faster way using dev tools? I do not want to override it with an !important tag, I want to find the origin and fix it.

Some people are pointing out this solution: Finding Javascript-Applied Inline Styles to Debug Javascript But this doesn't answer my question, as this shows you the code snippet causing the problem, but I'm looking for the source file name and/or path.

like image 292
desanddev Avatar asked Jan 06 '17 16:01

desanddev


People also ask

How do I find the origin source of an element style?

You should be able to find what styles are applied by using Chrome Devtools. In Chrome, if you right click on an element and "inspect," then view the styles in the "Computed" tab then you should see what styles are affecting the element.

How do you find the style of an element?

First, you need to select the element with querySelector . Then, you use getComputedStyle to get the element's styles. If you log style , you should see an object that contains every CSS property and their respective values. You can also see this object in Chrome's and Firefox's dev tools.

How can the style of an element be changed in JavaScript?

In order to change a style property of an element, change the value associated with the property under the "style" argument of the element. Let's continue with our button example from the last section: <input type="button" id="myButton" value="I'm a button!">


1 Answers

You should be able to find what styles are applied by using Chrome Devtools. In Chrome, if you right click on an element and "inspect," then view the styles in the "Computed" tab then you should see what styles are affecting the element.

example of computed tab

If you're looking for the injected javascript, try this previously asked question's answer. Here, Chrome Devtools DOM breakpoint is used to find the css.

Example image: enter image description here

After DevTools sends you to the "sources" tab it shows the first file that executes. However, if you click on the "Call Stack" drop down menu, it will show you all the affecting files, and if you click through them you can find the one causing the problem. When you get to the right file, DevTools will highlight the code that is affecting the page.

like image 51
Robotnicka Avatar answered Sep 18 '22 12:09

Robotnicka