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?
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?
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);
$item notation used in code I have worked on, even to indicate it contains a jQuery object. However, this usage might be arguably Apps Hungarian as the variable "represent a jQuery object" and not System Hungarian (which is normally considered "the bad kind"). The line is very blurred due to lack of static type information, of course.For me a common practice is this:
If a variable is private I use an underscore like this:
(function(){
var _foo = "bar";
})()
If it's public I'll use no underscore:
var foo = "bar"
And if it's a jQuery selector I'll use the $:
var $foo = $('bar');
//then you can access it like this
$foo.attr('id')
It's just coding convention and it allows you to quickly reference what type the variable is later in the code.