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
Mani Saini
3,101 PointsDifference between ID and Class
Could somebody please explain why class was used here and not ID :
<section>
<img src = "img/me.jpg" alt = "Photograph of Mani Saini" class = "profile-photo">
</section>
It would have done the same work?
1 Answer
Michael Hulet
47,913 PointsAn id is meant to be unique, whereas a class is meant to be applied to any number of nodes
Mani Saini
3,101 PointsMani Saini
3,101 PointsThanks Michael but i still didn't get why class was used? That pic is only used once anyways so it could be used with an ID ?
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsI'm not sure what video/challenge this was used in, so I don't know the context, but my guess is that it was either intended to be used again on another node, or it was just a design decision by the programmer. If a tag is only going to be used once,
idandclassare effectively interchangeable. You just reference them differently in CSS and JavaScript