30 September 2010
Use jQuery in Firebug
plus, it’s a great way to noodle around on a page you’re developing or some random page on the web. Now and again I find myself in the Firebug console, wishing that
jQuery was at my disposal, e.g., I want to manipulate the page in some way or print out a list of page content into the console (easy manipulation of data + copy and paste).
Normally you can’t do this unless the page is already using jQuery… unless you have a nifty bookmarklet that will add it to the page for you:
Here’s the bookmarklet Add jQuery Install it by dragging it to your bookmarks toolbar.
And here’s the code—pretty simple:
Now if I could just get Firebug to never crash Firefox…
Note: if you try to reference `$` from the Firebug console before loading jQuery onto a page, then it returns a function from within the Firebug code that’s just a wrapper around `document.getElementById`. Once you add jQuery to your page, you’ll only be able to reference it from the console as `jQuery`, since the other `$` now exists inside the scope of the console. On the other hand, if you load jQuery first, `$` should work as the jQuery object within the console.