I am not familiar with this syntax. What does the $.
mean before the function call?

- 67
- 1
- 7

- 5,214
- 21
- 65
- 94
-
Are you using jQuery? In this case it's just a shortcut for the jQuery() function. – Adriano Repetti Apr 26 '12 at 11:00
-
1possible duplicate of [Can someone explain the dollar sign in Javascript?](http://stackoverflow.com/questions/846585/can-someone-explain-the-dollar-sign-in-javascript) – Greg Bacon Apr 26 '12 at 12:14
5 Answers
$
is just a name of some object. It could be jQuery, or Prototype, in case you're using one of these libraries.
So $.functionName()
simply stands for calling a function named functionName
of the object named $
.

- 33,431
- 6
- 51
- 67
-
thanks for your comment. But which object would $ be? How do I know which object it is? – user840930 Apr 26 '12 at 11:05
-
@user840930 look at what javascript libraries are used on the page. First of all, look in the page source code and find all ` – Dmytro Shevchenko Apr 26 '12 at 11:07
-
Over here $ sign can be replaced with "jQuery " keyword.
$.functionName();
is the same as
jQuery.functionName();
if you are using jQuery framework. If using something else, it may refer to base object as in jQuery.

- 2,425
- 4
- 20
- 34
The dollar sign function has become the more-or-less de facto shortcut to document.getElementById().
http://osric.com/chris/accidental-developer/2008/04/the-javascript-dollar-sign-function/ Check this
And is used by Jquery, Mootools or any other javascript frameworks. Even you can make one
This is a small example
function $(obj) {
return document.getElementById(obj);
}

- 8,335
- 21
- 84
- 109
-
"De facto" standards should burn in hell. I've had enough fun watching people complain about Chrome breaking "de facto" properties order that "de jure" was always undefined. – Oleg V. Volkov Apr 26 '12 at 11:05
-
true, but its not the "De facto" problem, it's the browsers w3c implementation on html,javascript,css, the problem. – themhz Apr 26 '12 at 11:09
-
But before 3 years, the task of browsers keeping the "De facto standards" was worse. Now days things are much more better. – themhz Apr 26 '12 at 11:11
$ - is just an object name, since $ is valid symbol in JavaScript identifiers. This is not some special syntax, just a regular retrieving of 'functionName' property from object and calling it. Some libraries (like jQuery, for example) alias their main object to this short name to make calls take less space.

- 21,719
- 4
- 44
- 68
This is alias for JQuery object or Prototype or MooTools. Also you can see _. - Underscore.

- 5,530
- 6
- 27
- 44