$ vs. jQuery

Short Version:

Use jQuery, not $

Long Version:

When I was a younger man, I had to battle a rather complex bug in an application with 6 different JavaScript frameworks and different versions of each one.  It was a mess.

When you use $ you’re simply using that character as an alias for jQuery.  Lots of people use $.  People write blogs and books and write $.

However, prototype.js also uses that alias.

Only one can “win” and unfortunately many other 3rd party libraries, including JavaScriptSpellchecker.com, have prototype.js in its gooey center.  This means that any page that has the spellcheck on it could effectively take ownership of $ when you least expect it.  It’s awesome.

There is a workaround, which is to call jQuery.noConflict() before you go to use jQuery, but I think we all agree that’s rather silly.

So please, type out jQuery and not $.

Example:

jQuery.ajax()

 

It’s only 5 more characters to type…

// Dave

This entry was posted in Development. Bookmark the permalink.

One Response to $ vs. jQuery

  1. Rob says:

    _ = window.jQuery;
    window.$ = undefined;

    for example.

Leave a Reply

Your email address will not be published. Required fields are marked *