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 trialSaundra Howard
4,688 PointsSelector Specificity
Why is that when we needed to target the anchor within our nav the selector was "nav a" but when we needed to target the paragraph within our ID gallery we had to select "#gallery li a p" If we wanted to target the p element could we have also used "#gallery p" as a selector to target the paragraph? I hope that's clear.
3 Answers
Adam Little
6,735 PointsI think the idea is that you can't spell "specificity" without "specific".
Using '#gallery li a p' shows exactly where the paragraph element is nested in the Document Object Model (DOM).
justinburris111
7,836 PointsIt's just to make sure that the item selected is the one getting changed. It's making the selector more specific so that no other HTML attributes are changed.
Saundra Howard
4,688 PointsThanks Justin! It sounds like it's best to be as specific as possible so that we don't accidentally target the wrong element.
Nick Calabro
16,335 PointsThings like this didn't make sense to me at first either. I don't recall this exact course, but I imagine the code is pretty simple. Once you get to building bigger sites with a lot of different parts you'll find yourself being more and more specific like that.
justinburris111
7,836 Pointsjustinburris111
7,836 PointsBoom! Your first sentence hit it right on the mark!