I’ve inherited a pile of code that’s doing unexpected things when I click on some
Just press Pause button on the firebug panel (on the left-top corner of it, two yellow vertical lines, when Script tab selected) – and it will stops at first JS string.
But it will stop JS executing really at ANY event – so if you have a button which catches mouse move and mouse click – i will not be able to stop on mouse click, since script will be stopped at mouse move each time you try to move mouse over this button. I suggest you just to insert alert()’s in the suspicious places – after some iterations you will found exactly string you need (where error occurs).
I found a bookmarklet that will list all bound events in your page.
This kind be useful if you don’t know what events are bound by third-party code.
If you want to see what events are set up on the page, you might also try Eventbug.
... debugger; // Will trigger the debugger ...
Otherwise you can set breakpoints, conditional breakpoints, pause on the next execution, and all the usual tricks. Some nice videos are available here.
In response to the
alert suggestion before. I would seriously recommend using
console.dir if you have access to a debugger. You will get more information without blocking your script’s execution. Also, don’t forget that that
console.log can take multiple parameters so you can nicely print out data, you don’t have to constrain yourself to a single string like