Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The $ dollar sign

Tags:

jquery

I have something simple like this:

$(selector).append("somestuff"); 

But since I'm going to reuse the selector I cache it with:

var $selector = $(selector); 

So I end up with:

$selector.append("somestuff"); 

My question is, should I be doing that, or should I be doing:

var selector = $(selector); selector.append("somestuff"); 

Trying either one, both works. Which method is correct, and why? Is the $ in $selector unnecessary because the jquery object has already been declared in $(selector)?


Edit

Thanks for the answers. It seems very simple and quite clear. Still, there seems to be disagreement over whether or not I should use $ in the variable. It would be nice for everyone to vote up an answer. :)

like image 261
Mark Avatar asked Jul 24 '09 21:07

Mark


People also ask

What is the correct dollar sign?

Symbol for the American dollar in English Write the country symbol ( US ) first, immediately followed by the dollar sign ($) and the dollar figure: US$ 25.99.

Is the dollar sign 1 line or 2?

You may have heard that the dollar sign started as a U on top of an S, as in “United States.” Over time, the bottom of the U disappeared, leaving the S with two lines through it, which was eventually simplified to only one line.

What does the dollar sign symbolize?

It stands for the initials of the United States'.

What is a $1 called?

Buck is an informal reference to $1 that may trace its origins to the American colonial period when deerskins (buckskins) were commonly traded for goods. The buck also refers to the U.S. dollar as a currency that can be used both domestically and internationally.


1 Answers

$ is just a name - names in JavaScript can contain dollar signs, and can consist of just a dollar sign.

Whether you use a dollar sign in your name isn't relevant to jQuery - there's nothing special about the dollar sign, except that jQuery defines a function called $.

like image 126
RichieHindle Avatar answered Oct 07 '22 18:10

RichieHindle