Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
229,644 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
229,644 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.