Hacker News new | ask | show | jobs
by bhhaskin 1357 days ago
You shouldn't be using IDs anyways. They are just bad for a lot of reasons. You can only have one on a page and it reduces your reusability. Use classes instead.
2 comments

ID's aren't bad, they're unique identifiers, and useful for (deep) linking to specific pieces of content within documents. Please use ID's as liberally as you please, and use them for their proper use.
Use ids when JS needs to reference unique elements. Use classes for styling and accessing groups.
JS can do just as well with unique classnames, which avoids issues with ids like those given in the article.
I always presumed this would usually entail a performance hit, since you are accessing something that is not defined as unique.
It's an infinitesimal performance decrease, and it avoids a lot of other issues.