1

Possible Duplicate:
What is the meaning of symbol $ in jQuery?

i Want to know why using $ sign at beginning for example in jquery each function. What does difference between two of this..

$('.container').each()
/..and
$.each()

and I have been looking at code something like this..?? What the $ sign does??

 $.myObj = function() {
    /..
    }
Community
  • 1
  • 1
I am Andy
  • 163
  • 6

3 Answers3

4

The $ is not anything special; it's just an identifier that jQuery uses. The advantage of a very short name (instead of something like, say, jQuery) is that it doesn't unduly increase the download size of script files. Every byte counts (especially in the mobile world).

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • i see in many plugin use her function name like $.Twitter , $.myVar something like that Why using specific of $ – I am Andy Oct 24 '12 at 02:36
  • @IamAndy - jQuery plugins need to plug into the jQuery object, which is named `$`. That's all. The authors of jQuery chose `$` as the name, so that's what everyone else has to use. – Ted Hopp Oct 24 '12 at 02:37
1

You can even create your own! Although it's not the same, here is one that accepts IDs.

var SUPER = function(id) {
    return document.getElementById(id);
};

SUPER('exampleID').focus();

Now my input field with the id 'exampleID' will be 'focused'

But the $ is short hand for a jQuery object.

Jim
  • 1,274
  • 1
  • 10
  • 15
0

In javascript, functions can be executed by calling them, but they are also objects and they can contain properties. Those properties can either be data or they can be other functions.

In jQuery, $ is just a function that you can either call as a function as in $(".whatever") or you can access properties on the function. Those properties are either functions themselves or, in some cases data. $.each() is a function that is a property on the $ function object.

In jQuery, $ is just a shortcut (to save typing) for the main jQuery object.

jfriend00
  • 683,504
  • 96
  • 985
  • 979