There is no need to use $
at the beginning of variable names and some developers actually hate the practice altogether, though I do personally like it. The common use is to note that the value of that variable is a jQuery object.
A jQuery object is what is created in this process:
var $myElement = $('#some-id');
That notes that $myElement
contains a jQuery object and therefore it is safe to use jQuery functions on it. For example, $myElement.hide();
Without jQuery, this is how the same code might look:
var myElement = document.getElementById('some-id');
myElement.style.display = 'none';
In that case, myElement
is NOT a jQuery object and so myElement.hide()
is an error. This is an example of why someone may prefer to have the $
on the variable name... to note that jQuery functions can be called on it. If someone is using jQuery already, it is standard to get all element references with jQuery anyway, so this actually is redundant.