Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Leandro Severino
Leandro Severino
12,674 Points

What does "$()" mean?

I was checking the docs of one library and it has codes like...

$().w2grid(config.grid2); URL: http://w2ui.com/web/demos/#!combo/combo-1

I want to know what the $() does.

That is most likely jQuery shorthand for $(document).ready();

So the script will only execute once the DOM has been fully loaded/finished loading

Steven Parker
Steven Parker
220,415 Points

It is not a shorthand for "$(document).ready()" unless it is given a callback function as an argument ("$(callback)").

2 Answers

Steven Parker
Steven Parker
220,415 Points

"$()" is a shorthand for "jquery()".

Here's an excerpt from the jQuery API manual:

jQuery() — which can also be written as $() — searches through the DOM for any elements that match the provided selector and creates a new jQuery object that references these elements: If no elements match the provided selector, the new jQuery object is "empty"; that is, it contains no elements and has .length property of 0

In this case, the empty jQuery object is being used to access the w2grid method of the w2ui jQuery plug-in.

Leandro Severino
Leandro Severino
12,674 Points

Thanks! I'm just confused coz I don't know the reason(yet) for using "$()" which just returns an empty set.