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 jQuery Basics (2014) Introduction to jQuery What is the DOM?

Tony Brackins
Tony Brackins
26,688 Points

$ in JQuery

$ = JQuery

$ (".warning") = document.getElementsByClassName("warning")

How does JS know whether to choose the document or JQuery? Or is JQuery the same as document?

5 Answers

morgan segura
PLUS
morgan segura
Courses Plus Student 6,934 Points

jQuery is a JavaScript library. Technically you could do: var warningElement = $('.warning'); or var warning = document.getElementsByClassName("warning"); So to answer in full, yes you are correct $('.warning') and document.getElementsByClassName("warning") are the same. jQuery makes it easier for us to all on DOM elements.

Also, you don't have to use the dollar sign, jQuery('.warning') is the basic usage, but the dollar sign is easier and common practice.

Daniel Botta
Daniel Botta
17,956 Points

$ (".warning") and document.getElementsByClassName("warning") are the same thing. You will get the same result from both of them.

Basically one of the many things that jQuery does is that simplifies the syntax of many of the features that JavaScript already offers.
$ (".warning") is really just jQuery's more simplified shorthand version of document.getElementsByClassName("warning").

I hope this helps answer your question!

$ is the short hand for jQuery. You can use the $ to access jQuery's methods. By using $("#someElement") You are using jQuery to select an element on the page.

Maybe this will help?
http://stackoverflow.com/questions/10787342/why-does-jquery-have-dollar-signs-everywhere

Aaron HARPT
Aaron HARPT
19,845 Points

I believe that they are equivalent. hope that helps.