views:

183

answers:

3

I am working on a site that has loads of legacy javascript and jquery includes and there is no documentation to show what is happening when.

I have a specific problem to fix and I cannot find the relevant code that is being executed when a button is clicked. To save me from trawling through (and making sense of) hundreds of lines of legacy script, is there a feature, possibly in Firebug, that will identify what script is being executed when I click on a button?

Thanks for your help.

+1  A: 

I believe there is a feature in Firebug's console window called Profile. Click profile, click the button, then click profile again. It should give you what all functions were called in that time. Be warned that if this code includes jQuery, you might get a huge long list of functions because jQuery uses tons in its code. Unfortunately, the profiler will also show anonymous functions, which can really be a pain.

Otherwise, do a search in the code for the button's class or ID and go through them. If you have an id of fancy then you might do a search for #fancy in your code and attempt to find it. That may lead you in a general direction, at least.

Reid
That's done it - exactly what I was looking for - even if the output is pretty long! Thanks very much to everyone for your help.
Kevin
This really is a great place for developers - I'm very grateful for everyone's time and skill.
Kevin
A: 

In Firebug you can set a breakpoint in some JS and then you get a stack which will let you know the current function call stack. So if you set the breakpoint in function used by several handlers then you can use this to discover exactly which handler you are in.

This probably won't work if you are dealing with AJAX callbacks and the like though.

workmad3
Should note that the stack feature is not available in Firebug for Firefox 2 (IIRC).
Crescent Fresh
A: 

You can click Firebug's "Break on next" button (in the Script tab; it looks like a pause button), then push the button that you want to debug.

The next time any JavaScript code executes, Firebug will break into the debugger and show you that line of code.

Jason Orendorff
Aha, so that's what the pause button does :D I'll have to remember that one
workmad3