Search code examples
javascriptjqueryvariablesdollar-sign

When/why to prefix variables with "$" when using jQuery?


Possible Duplicate:
Why would a javascript variable start with a dollar sign?

I see people using the dollar sign in front of variables when using jQuery. Is there any reason behind this? I'm I missing something basic or is it just a common practice?


Solution

  • It's a common reference to a jQuery wrapped object. It makes reading the code easier to know which variables are jQuery wrapped.

    //Item has been "cached" for later use in the script as a jQuery object.
    var $item = $(this);