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

What kind of code is "document.queryselector"? When I search JavaScript statements, I get DOM returns instead.

In addition, as it is a "selector", does that imply it is CSS? Meaning, does Javascript generally understand CSS selectors? And, if so, what other languages understand CSS selectors?

3 Answers

Nikos Papapetrou
Nikos Papapetrou
6,305 Points

document.querySelector() is a method being use by JavaScript to access the HTML DOM: https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction. You can access it also with css class, ids, tag names etc.

<button id="my-button" class = "btn-class"></button>
document.querySelector('button');  // tag name 
document.querySelector('#my-button');  // id
document.querySelector('.btn-class');  //class

You should look the course about DOM manipulation. It is a big topic and there are other methods you should learn. I think all the languages have their own methods to access the html dom, but JavaScript is widely used for it.

Thanks for the thorough answer Nikos! I thought it must be related to Document Object Model from searching, but I'm not confident about everything I'm seeing yet of course. I am taking notes though, and am going to include your answer in my file. I haven't gotten to DOM manipulation yet, but I will!

Nikos Papapetrou
Nikos Papapetrou
6,305 Points

No worries! Glad to help you!