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 trialDongyun Cho
2,256 Points.addClass('red') vs .attr('class', 'red')??
I just wonder, why I cannot set attribute class="red", with .attr function instead of adding class called 'red'.
1 Answer
Steven Parker
231,269 PointsYou can use attr to set the class.
But if you do, you will remove any other classes the element had already. So normally you would use addClass instead since it preserves other classes of the element.
This doesn't seem related to the challenge you linked to.
Dongyun Cho
2,256 PointsDongyun Cho
2,256 Pointsthanks for the answer!