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 trialDylan Merritt
15,682 PointsWhat is the difference between using a descendant selector and using the :only-of-type selector?
If there is only one of a type in a class, it seems to me that using a descendant selector and using the :only-of-type selector would accomplish the same thing, and that it would be easier to use a descendant selector. Is there any real difference between the two?
1 Answer
Steven Parker
231,269 PointsGiven the simple case described, there would be no functional difference. The differences would be in specificity (higher for :only-of-type) and browser compatibility (universal for descendant).
But more important would be what behavior would you intend for when another element of that type is added? At that point the :only-of-type would no longer apply at all, but the descendant would apply to both elements.