Subscribe to RSS Feed

Here is a brief tip post about the well known Firebug's inspector feature and its integration with the command line.

You need Firebug 1.7a4 that fixes a bug in command line APIs (the fix will be ported into 1.6b3)

Inspector button

When the inspector is used to inspect the current page, Firebug is automatically keeping a history of recent inspected elements. The history is consequently accessible in the command line through following command line APIs.

  • $0 The currently selected object in the inspector.
  • $1 The previously selected object in the inspector.
  • $n(index) Access to an array of last 5 inspected elements.

So, you can use $0 as a variable pointing to the currently inspected element and pass it to another functions or access it's properties.

For example, right click on the above screen-shot and pick Inspect Element. Switch to the Console panel and use $0 in the command line to get number of attributes.

Inspector button

jQuery in the command line

Here is another example that uses jQuery APIs in the command line. The $0 element is passed into the jQuery function as a parameter (slideUp method animates the height of the element).

Inspector button

If the current page doesn't use jQuery, you can install it quickly using a jQuerify bookmarklet.


Rss Commenti

12 Comments

  1. How does this interact with the global variables $0, $1, $n?

    #1 fearphage
  2. [...] Software is hard | Firebug tip: Inspector History & Command Line [...]

    #2 Command And Conquer Tiberian Twilight Rapidshare Free Full … | New Twilight
  3. @fearphage my bet is it probably makes it hard to access them... window.$0 should grab it in Firebug. The open issue of $ being stolen by firebug is not looking resolvable.

    It's also worth noting that these tricks work in webkit inspector (chrome/saf) as well! yay for interop!

    #3 Paul Irish
  4. [...] Software is hard | Firebug tip: Inspector History & Command Line [...]

    #4 Command Prompt in Windows | All Computer Problem
  5. [...] Software is hard | Firebug tip: Inspector History & Command Line [...]

    #5 Basic Linux Commands | All Computer Problem
  6. @fearpage, Paul Irish: these variables (and all the other command line APIs) are defined within _FirebugCommandLine object and executed using:
    with(_FirebugCommandLine) {/*cmd line expr*/}
    What do you mean by "The open issue of $ being stolen by firebug"?
    If "$" is already defined on the page, Firebug doesn't override it.
    Do you have a test case?

    #6 Honza
  7. [...] Software is hard | Firebug tip: Inspector History & Command Line [...]

    #7 GFI Software to Migrate Network Security Inspector Technology Users to GFI LANguard™ | Network Security
  8. [...] are… history la inspector. E o treabă de care habar n-aveam dar care mi-ar fi fost de folos de nenumărate [...]

    #8 Link-urile săptămânii 18-24 octombrie | Staicu Ionuţ-Bogdan - the Frontend Developer
  9. keeping a history of recent inspected elements is a great feature of firebug

    #9 clasamente
  10. How can _FirebugCommandLine be accessed from the own extension module?

    #10 Antonio Banderas
  11. context.window.wrappedJSObject._FirebugCommandLine doesn't intend to work. The $0 could be accessed via _FirebugCommandLine.$0 as $0 is declared from __defineGetter__

    #11 Antonio Banderas
  12. [...] Fixed command line API for inspector history (see more). [...]

    #12 Firebug 1.7a4 released - Open News

Sorry, the comment form is closed at this time.