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

$ 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

Got it. thanks guys!

Aaron HARPT
Aaron HARPT
19,845 Points

I believe that they are equivalent. hope that helps.