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 trialcloud712
7,616 PointsWhy 'p.description'?
const p = document.querySelector('p.description');
Could someone help me understand what the 'p.description' means?
'description' is a class, so the dot notation makes sense. I'm confused why it needs to be preceded by a 'p', though.
2 Answers
Joseph Yhu
PHP Development Techdegree Graduate 48,637 PointsBecause there are also an input
and a button
elements with class description
directly below the p
element with class description
, and you only want to select the p
element with class description
for that particular code.
cloud712
7,616 PointsAh got it. So if I wanted to select all elements with the class description, then I'd use this instead? (obv it wouldn't work with the code from the class, but I just want to understand)
document.querySelectorAll('.description')
Joseph Yhu
PHP Development Techdegree Graduate 48,637 PointsYes.
cloud712
7,616 PointsThanks Joseph Yhu !
cloud712
7,616 Pointscloud712
7,616 Points(code is from the video)
index.html
app.js