Why do we still use element ID's in HTML if classes are more flexible and do the same thing? -


lets assume making brand new app. make view/template/css/js like, there nothing pre-defined, there no structure. can use whatever selector desire, including classes/data-attribs, in helper libs.

so question: what purpose of using id's when classes/data-attribs more flexible, reusable, , easier "stack"? assuming building scratch, have concise reason element id absolutely needed? why still insist on using them in code?

i see no point whatsoever using id....ever. quite frankly cause validators yell @ misusing them. maybe i'm missing golden egg , enlighten me why still use element id's in our apps , things.

id less flexible class. that's advantage, not failing. when give id rather class, can rely on being unique , unambiguous (if document valid). if refer element in css or javascript, know you're going single element. because of this, there lots of functions , frameworks rely on id (as comments on question indicate).

there's performance difference: it's faster reference ids (because they're unique) classes, because find instances of class need traverse whole document. see this answer.


Popular posts from this blog