4

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

Logan Cerson
  • 67
  • 1
  • 7
user840930
  • 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
  • 1
    possible 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 Answers5

7

$ 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 $.

Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67
3

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.

SadullahCeran
  • 2,425
  • 4
  • 20
  • 34
2

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);
}
themhz
  • 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
1

$ - 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.

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68
0

This is alias for JQuery object or Prototype or MooTools. Also you can see _. - Underscore.

Denis Ermolin
  • 5,530
  • 6
  • 27
  • 44