Catching the specific javascript code being executed onClick

Kevin picture Kevin · Jan 13, 2010 · Viewed 11.6k times · Source

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.

Answer

Reid picture Reid · Jan 13, 2010

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.