2

Let's say my source HTML looks like this:

<div id="whatever">...</div>

But my Chrome inspector shows it to me like:

<div id="whatever" class="random-class">...</div>

I can assume that that .random-class was added by a Javascript script, but there are dozens of these scripts on the site. Is there any "standard" way, using the Chrome or FireBug inspector for example, to determine which script is adding this class to my element?

3
  • are you doing this on a large scale or just for one or two elements and classes? Commented Jun 19, 2015 at 14:35
  • In your editor, find the "find in files" option and in the find box type "random-class" - results should appear if it's in any file within a parent folder. Commented Jun 19, 2015 at 14:37
  • possible duplicate of jQuery - Fire event if CSS class changed Commented Jun 19, 2015 at 14:41

2 Answers 2

1

with the webkit inspector in chrome, you can use Ctrl-Shift-F and search for "random-class". It will give you all the matches, distincted by file.

You can go through the results one by one and find the cause, even put breakpoints. If this is too much of a pain you can try to find className += "random-class" or for jQuery addClass("random-class") etc.

If you are looking at results in minified code, chrome allows you to prettify the result, after which you can re-search. So if you have a minified file with 1 line function x() { document.body.className += "random-class"; };x();document.body.className += "random-class"; the match will show 1 line. Then prettify the code and re-search. Now the results will show in 2 different lines.

Sign up to request clarification or add additional context in comments.

Comments

0

If you're going the browser route, a browser extension like FireBug will show you the events attached to the element like 'change()' etc. However, be aware that some embedded scripts won't show up here. I'm assuming these are all external scripts.

You can also use Visual Event by SpryMedia. However, this is sort of heavy duty if you need to do this for a huge site. It also comes in a browser extension.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.