JavaScript
Use Firebug to Break on Any Event
Last Updated (Wednesday, 17 September 2008 06:59) Written by Alex Grande Thursday, 28 August 2008 05:26
Oftentimes it's helpful to set a break point in Firebug when a certain event happens on a page. Say you are inspecting foreign code and don't know which function is called, but you want to set a breakpoint right when an event happens. This short script allows you to break on any event using the simple syntax: breakOn(id, event) // e.g. breakOn('nav', 'onhover')
For those of you unfamiliar with bookmarklets, they are short snippets of JavaScript code that you can execute like a bookmark in your web browser. Here are instructions for adding this short script to your browser as a bookmarklet:
1. Go to http://www.alexgrande.com/breakable/ and add the link to your bookmarks.
2. Go to the page you are interested in inspecting and click on the bookmark in your browser called "Inspect JS". That will load breakable.js into the head of the page you are currently using.
3. In Firebug go into the scripts tab and view breakable.js.
4. Set a break point on line 7 where it says funct();
5. Find out what the ID is of the element that has the event listener.
6. Click the console tab in firebug. Type in: breakOn("elementID", "eventTrigger"); Example: breakOn("prettyImageOver", "onmouseover"); Example 2: breakOn("ajaxImageChanger","onclick");
7. (1) Initialize the event by mousing over it or whatever you you chose as the event trigger. If the original js author chose a mouse over event then you should also use a mouse over event. Because if you choose an onclick for an onmouseover event then by the time you click it the event has already passed you by.
8. (2) Firebug will transfer over to the breakable.js in the scripts tab at the breakpoint funct(). Step into it by (3) clicking the arrow right in Firebug script section.
9. and you will enter into the JavaScript code of whatever function is called by the event.
I love this! Big thanks to my friend Grady Morgan for writing this short but incredibly useful script!



