commandline

Firebug and the Command Line

The command line is one of the oldest tools in the programming toolbox. Firebug gives you a good ol' fashioned command line for JavaScript complete with very modern amenities.

Get your hands dirty

If you know your way around the DOM, sometimes there's no faster way to get answers than to just use JavaScript to snoop around. Firebug's command line lets you do just that - enter whatever JavaScript you like. It will be executed as if it were part of the page, and the returned values displayed in the console.

Autocomplete

The autocompletion of the command line is very powerful. A popup shows a list of all available properties for an entered expression. Using Tab or Enter you can autocomplete the selected suggestion. You can cycle through the different suggestions via Up, Down and other navigation keys as well as the mouse wheel.

Autocomplete works at many levels. After typing "document.b" you see all properties of document that start with "b". It even works for complex expression like "document.getElementsByTagName('a')[0]." giving you all properties of the first link in the document.

Go big

If one line is making you feel a little cramped, don't panic. Firebug's command line can be expanded to a larger text editor so you can experiment with entire scripts instead of just one-liners.

Smart paste

So you've written a bunch of JavaScript in your editor and you want to test it out real quick. Just paste it into the command line. If it's more than one line, Firebug will automatically open the big text editor with your script ready to go.

Bookmarklet heaven

Creating bookmarklets has never been easier. Just hit the "Copy" button in the multi-line editor and your script will be copied to the clipboard in bookmarklet format.

Don't forget to click

Unlike a traditional command line, the output of each command is not static text, it is living hypertext. Any objects that are output to the console are hyperlinks that you can click to inspect the object in whichever Firebug tab is most appropriate.

Don't forget to right-click

Context menus contain a whole world of fun features waiting to be discovered. Different kinds of objects have their own context menus, so when you see a link to an object in the Firebug console, try right-clicking it.

Don't forget to middle-click

If you haven't already learned the magic of middle-click and tabbed browsing, now is a good time to learn. Just like when you middle-click a link in the Firefox browser, middle-clicking a link to a file or URL in the Firebug console will open it in a new tab.

For those without a middle mouse button, you can also hold down the control key (or command on Mac) and click for the same effect.

Be a commander

The Command Line holds many commands providing you with a wide variety of functionality. E.g. it allows you to include external JavaScripts, monitor JavaScript events on objects, clear the console, etc. Just type "help" and hit Enter to see a list of them.

Inspect and command

After you've found an HTML element using the Inspect tool, you often want to use the command line to manipulate it. Firebug makes it easy; just use the $0 variable to reference the last element you inspected, or $1 for the one before that.

There are many more commands providing you with a wide variety of functions. Just type "help" and hit Enter to see a list of them.

Command and inspect

The command line is a wonderful launching pad for using the other tabs to inspect objects. Instead of hitting enter to see the result on the console, hit Shift+Enter and the result will be inspected in either the DOM tab, the HTML tab, the Script tab, or the CSS tab, whichever is most appropriate.

Command Line History

The command line maintains its own history of executed expressions and so, you can easily go back and execute an expression again. Just use up & down arrows or click on the red button on the left side of the command line to see a history popup with all entries.