I have something simple like this:
$(selector).append("somestuff");
But since I\'m going to reuse the selector I cache it with:
In this case, $selector
is an example of Hungarian notation. It is there so that you know that $selector
is a jQuery object.
If you make it your custom to always have jQuery objects start with $
if you suddenly use one wrong it will look wrong which will help you find a problem in your code.
The language couldn't care less. They could have just as well named the jQuery function J
or anything else; the $
is not a special symbol.
The cash sign is just an alias for the jQuery function. Starting the variable name with $ has no effect on that variable.
It is customary though, especially in jQuery plugin development, to use variables already wrapped in jQuery with a cash sign, so you know you can call jQuery methods, without having to wrap them.
Yeah.
jQuery always returns a jQuery object. It's what allows chaining.
You've already defined the variable so you get a jQuery object back so $ is unnecessary