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?

0

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Since all functions are also objects in JS, I called it a function. In any case, I've enhanced my choice of wording.
2

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

1 Comment

This answer is just repeating parts of the question. Why are people upvoting it?
1

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

3 Comments

To understand recursion, one has to first understand recursion.
+1 this is the only completely right answer so far.
@Cularis - This is what they call out of the box solution.
0

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.