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<noob />
17,062 Pointsquestion about querySelector
evreytime i use querySelector to get an access to an input or a button i need to first name the kind of the thing and then the class name?
for exmaple:
const descriptionButton = document.querySelector("button.description");
const addItemInput = document.querySelector("input.addItemInput");
const addItemButton = document.querySelector("button.addItemButton");
const descriptionP = document.querySelector("p.description");
u see?, lets take the descriptionButton for example. he has a class name "description" and to access it we do button.description why we cant for exmaple query this by using getElementbyClassName("description")?
1 Answer
Adam Pengh
29,881 PointsYou can use querySelector with just the class .description, but you need the period to indicate it is a class selector
document.querySelector(".description");