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 trialPaolo Di Pasquale
4,251 PointsAttribute Selectors
If the browser has to work harder to select elements using attribute selectors such as
input[type="text"]
would it be more efficient to add a class to that element in the HTML instead?
3 Answers
James Barnett
39,199 PointsLittering your HTML with classes can cause headaches with maintainability which is important on large projects where more than one person is writing code.
Sometimes when working on the frontend of an application you might not have access to the markup it might be generated for you, so for workflow reasons it's simpler to write CSS rather then filing a request to have a class added to an element.
James Barnett
39,199 Points>
would it be more efficient to add a class to that element in the HTML instead?
No.
The days of worrying about selector performance are gone
http://calendar.perfplanet.com/2011/css-selector-performance-has-changed-for-the-better/
João Pedro Nascimento
1,407 Pointssure, this type of selector is best used in small projects. taking into consideration the performance
Paolo Di Pasquale
4,251 PointsPaolo Di Pasquale
4,251 PointsThat makes sense, thank you.