3

I'm wondering if it's possible to find out which jQuery script is affecting a particular element on a page.

I can see jQuery affecting a div, but can't find which script is manipulating the div - Is there a way to find out?

2 Answers 2

4

Use Firebug. Inspect the element, right-click the div in the HTML, then choose log events or one of the break options.

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

1 Comment

Fantastic, never knew this existed.
0

There is no easy way to find that what code changes an object other than just searching through the code and finding code that looks like it might be affecting the object, setting breakpoints and stepping through the code to figure out what it does and when.

Usually, you can find out which part of the code is using selectors that could be targeting your specific div. Searches through all the code for various id values or class names will often find the general area of the code.

If there are HTML event handlers like onclick="xxx()" in the code, you can obviously track down where those functions are in the code. If the code is using event handlers assigned via javascript, then you can often find the initialization code that runs when the document is ready and see what event handlers are getting assigned and try to set breakpoints in those callbacks.

There really is no other way besides studying the javascript to find out what code is responsible for the effect you're interested in. To do this seriously, you copy/paste all the scripts from the site into one big file, then use a beautifier like http://jsbeautifier.org/ to format it uniformly and readably and then study it. I like to make a copy of the code into a separate file and then go through it piece by piece removing pieces of code I'm sure have nothing to do with what I'm looking for. Slowly over time, I end up with only a few bits of code left, one of which has what I'm looking for. It is like looking for a needle in the haystack, but if you keep throwing out pieces of hay eventually, there isn't much hay left for the needle to be in. As you start to learn the code, you can also find relevant things to search for in the remaining code to make your search faster.

3 Comments

Ah I saw an effect on msn.co.uk and wanted to take a look at how it was done so I could manipulate/ write my own but I can't find the script that affects it.
@user1277454 - I added a paragraph to my answer on how I do it.
Thank you. I guess I need to just expand all scripts on Firebug and get all the code. Going to take a while but will be worth it.

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.