What does the $ sign mean in jQuery or JavaScript?

Possible duplicate:
What is the meaning of the $ sign in JavaScript?

Now this should be a simple and silly question, but I should know why we use the dollar sign ( $ ) in jQuery and JavaScript. I always put a dollar in my scripts, but I, actuary, don't know why.

For example:

 $('#Text').click(function () { $('#Text').css('color', 'red') }); 

It just changes the color of the text when you click on it, but it demonstrates my point.

+57
javascript jquery
Dec 29 '11 at 12:12
source share
6 answers

In JavaScript, this does not really matter (no more than a or Q ). This is simply the name of an uninformative name .

In jQuery, a variable is assigned a copy of the jQuery function. This function is heavily overloaded and means half a dozen different things depending on what arguments it is passed. In this particular example, you pass it a string containing the selector, so the function means "Create a jQuery object containing an element with id text".

+47
Dec 29 '11 at 12:13
source share

$ is just a function. This is actually an alias for a function called jQuery , so your code can be written in the same way with the same results:

 jQuery('#Text').click(function () { jQuery('#Text').css('color', 'red'); }); 
+37
Dec 29 '11 at 12:14
source share

The jQuery syntax is for selecting HTML elements and performing some actions on the element (s).

Basic syntax: $ (selector) .action ()

Dollar sign to define jQuery A (selector) for the "query (or search)" of HTML elements Performing jQuery action () for element (s)

More on this

+9
Dec 29 '11 at 12:15
source share

In jQuery, the $ sign simply means the jQuery() alias and then the function alias.

This page reports:

Basic syntax: $ (selector) .action ()

  • Dollar sign for jQuery definition
  • A (selector) for the "query (or search)" of HTML elements
  • Performing jQuery action () on element (s)
+6
Dec 29 '11 at 12:24
source share

The $ character simply invokes the functionality of the jQuery library selector. Thus, $("#Text") returns a jQuery object for the Text div which can then be modified.

+3
Dec 29 '11 at 12:14
source share

In addition to jQuery discussed in other answers, JavaScript has a different meaning - as a prefix for RegExp properties that represent matches, for example:

 "test".match( /t(e)st/ ); alert( RegExp.$1 ); 

will warn "e"

But here it’s not β€œmagic”, but just part of the name properties

+2
Dec 29 '11 at 12:18
source share



All Articles