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 jQuery Basics Working with jQuery Collections jQuery-Specific Selectors

The purpose of $, in const$(element).

I don't quite understand why they use $ at the beginning of constant$(element)?

1 Answer

Steven Parker
Steven Parker
231,261 Points

The $ is a convention for jQuery. So while not technically necessary, it's common to use one at the beginning of any variable name that will be used to reference a jQuery object.

It's also an abbreviation for jQuery itself, so when you put something in parentheses after a single $, it calls jQuery and passes what's between the parentheses as an argument. So for example:

const $obj = $(element);

This would pas "element" to jQuery, which will convert it into a jQuery object, and then assign that object to the variable "$obj".