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 One Solution

I thought we had to use the ID (#) and class (.) identifiers when we get elements, but here, we didn't have to.

I think I'm just confused as to when we were supposed to use them while using the dom.

2 Answers

Steven Parker
Steven Parker
231,236 Points

When you use the generalized selector functions "querySelector" and "querySelectorAll", the "#" and "." identifiers are used to distinguish id's and classes.

But when using the specialized functions "getElementById" and "getElementsByClassName", those are not used since each function already targets only one specific kind of thing.

Thank you, that makes so much sense! I guess it would have helped if I would have spent a little more time looking at the HTML to know what I was querying!