1

I'm following the beginners tutorial on jQuery called How jQuery works. After a couple basics a function is presented: $.get( "myhtmlpage.html", myCallBack );. I understand how it works and all, but I just don't understand why this function starts with $., instead of simple being get("myhtml... etc.. Googling for it doesn't result in any results, I guess because Google doesn't take $. into account.

So my question, why do (some?) functions in jQuery start with $.?

kramer65
  • 50,427
  • 120
  • 308
  • 488
  • 1
    http://stackoverflow.com/questions/1150381/what-is-the-meaning-of-sign-in-javascript possible duplicate – sumit Jan 26 '14 at 10:10

4 Answers4

4

The $ is a shorthand for the jQuery object itself.

see this discussion:

$ versus jQuery

Community
  • 1
  • 1
DrLivingston
  • 788
  • 6
  • 15
3

Functions starting with $. are utility methods and not specific DOM elements. Examples include $.ajax, $.each etc.

Where as others like $('#domID') manipulates that specific DOM element like $('#domID').fadeIn() etc.

1

The alternative would be to create dozens of global variables using the names of common words, and that is highly likely to conflict with other variables from other scripts on the page.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

The one should read "$.get" as: "$" is a namespace, "get" is a function within "$" namespace. Somewhat similar to static member functions in C++ and Java.

akhikhl
  • 2,552
  • 18
  • 23