Once installed, you can activate Firebug when you press the F12 key. You are now ready to debug your code.
A good way to start is to create breakpoints in your script. These breakpoints allow you to run through the code and pause so you can examine the value of each variable to help you find the problem. To create a breakpoint:
- Click on the green check button to toggle the Firebug debug panel
- Switch to the script tab
- Scroll to the desired line and set a breakpoint by clicking on the left sidebar
- Reload the page
You can step through your code a line at a time using the step over function. With each line, you can check the current value of any variables to help you determine if any of them are the cause of the problem.
An alternative method that you can use to set breakpoints is to use the following line in your code:
Another useful feature of Firebug is the ability to display script output. You can use an alert message box, which will pause script execution, or the console.log function. This example demonstrates the use of this function:
console.log(“Title: %s, page: %d”, title, page);