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 trialrachaelallison
9,521 Pointswhy would we be unable to add a class or ID to an HTML element?
In this video, Gil mentions a use of the substring attribute selectors might be when we can't add an id or class to an HTML element. Why would this happen?
1 Answer
Kevin Korte
28,149 PointsSometimes when you're using a content management system, or a plugin, or anything that generates it's own html, you might not have control of the classes and ids when the code is being generated on the fly. In those case, attribute selectors come in very handy.
jason chan
31,009 Pointsjason chan
31,009 PointsTo add frameworks like laravel. you have to add classes through an array through php. NOT HTML ANYMORE. lols.
Ginger Bidwell
12,289 PointsGinger Bidwell
12,289 PointsEven when you can modify the generated markup for a content management system it's not always the most efficient way to solve the problem - sometimes duplicating markup templates can have negative consequences for long-term maintenance.
One example of a case where you'd be unable to change the markup of something you were working on might be a legacy closed-source system. With opaque systems that are made out of antiquated tech, it can be difficult to find people who can work on changing the HTML. In those cases, attribute selectors make it possible to change the visual look of the page more drastically without adding more technical risk.