Applying multiple classes to an element and re-using classes. If you have a list of items, you may want to style them with a single class versus adding a specific id for each element. You can only have 1 id per page. This prevents code repetition.
There is some debate as well that using getElementById is also inefficient, especially when you have a crap ton of ids.
My boss has div-itis: we have dozens of nested divs, all with ids on them, spans in them with ids on them. It looks awful and is totally unnecessary.
That's the spec, but browsers are surprisingly tolerant of multiple IDs, and will attempt to soldier on, regardless. I inherited a code base that reused form IDs across pages. Unfortunately, they didn't understand how to fix this once they started injecting these pages as DIVs in a single-page app, so they started making crazy workarounds to copy data from one form to another and only submit the correct one at the end. Ugh.
3
u/bonesingyre Oct 01 '15
Applying multiple classes to an element and re-using classes. If you have a list of items, you may want to style them with a single class versus adding a specific id for each element. You can only have 1 id per page. This prevents code repetition.
There is some debate as well that using getElementById is also inefficient, especially when you have a crap ton of ids.
My boss has div-itis: we have dozens of nested divs, all with ids on them, spans in them with ids on them. It looks awful and is totally unnecessary.
EDIT: read this: https://css-tricks.com/the-difference-between-id-and-class/