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 trialEdelweiss Villoria
4,801 PointsWhat EXACTLY does document.querySelector do?
What EXACTLY does document.querySelector do?
1 Answer
Emily Venturino
1,288 PointsEmily Venturino 2 minutes ago when you use document.querySelector() it looks at your script and finds any results matching the parameter you pass to the ().
for example, the following line will look through your script and bring back the text of an element with the ID named "example" : document.querySelector("#example")
you can then use what you have selected and manipulate it. For example, the following line would search for any element with the ID of "example", and give it a red border. document.querySelector("#example").style.border = "10px solid red";
hope that helps!