0

Possible Duplicate:
What is the $ in jQuery?

We know that $ is an alias of jQuery, while using jQuery javascript framework.

But internally what $ is ?

I mean whether it is an object, function or other thing?

Community
  • 1
  • 1
Jatin Dhoot
  • 4,294
  • 9
  • 39
  • 59

5 Answers5

2

$ is a function object in jQuery. It can take a number of different types of parameters or methods. That's why you will see things like:

$("#content")

In that use, it's just a function - identical to:

jQuery("#content")

In this example, it returns an object that contains both the collection of DOM items matching the passed in CSS string and has a whole bunch of methods that let you operate on that collection of items it returned such as:

var html = $("#content").html()

to get the innerHTML of that DOM object.

It is usually used like a function $(params), but can also has methods as an object $.get().

But, most of all $ is just a symbol for a function object that also has methods. It could be called foo or anything else so it's not anything unusual in Javascript.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Not *just* a function. E.g. you can do `$.get('myhtmlpage.html', myCallBack);` which would not be possible unless `$` were also an object. See @Steffen's answer. – LarsH Jul 15 '11 at 07:46
  • Since all functions are also objects in JS, I called it a function. In any case, I've enhanced my choice of wording. – jfriend00 Jul 15 '11 at 07:50
2

$ is just and alias. Its same as jQuery Object. That is its reference to jQuery Object.

sushil bharwani
  • 29,685
  • 30
  • 94
  • 128
1

$ is an object, just like jQuery is. Besides, all objects in javascript are functions and all functions are objects.

Steffen
  • 2,235
  • 13
  • 19
0

$ is a variable in exactly the same way that jQuery is a variable. And its value is a function.

Peter
  • 127,331
  • 53
  • 180
  • 211
0

It's just a pointer to the JQuery prototype function.

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145