Wednesday, December 14, 2011

Use jQuery in Chrome Console

Since Chrome in gaining momentum (and Firefox losing it) I though I'd start using it in my new laptop and don't even download FF.

I have been quite happy so far, but I just discovered a caveat: if you are using the Console to quickly test some HTML / JavaScript / jQuery / CSS, then be aware that the Chrome Console will replace jQuery's $ function with it's own, that is actually an alias to getDocumentById.

To quickly check it, just use jQuery===$ and see the output. Or if you just enter $, Chrome should have changed that function to the following:

function () {
     return document.getElementById.apply(document, arguments)

That means if you select an id it would actually return what you expect, but everything else will fail. So just use jQuery() for your quick test in the Console, and that's it!

EDIT: this bug is already fixed (here), so the problem must be another one. In Twitter, @fbatista answered me with the most probable option: a misplaced $.noConflict()!

No comments:

Post a Comment