Why not just always use class instead of ID?
I understand that ID is for something you will only use once - and it has more weight than a class. But why not just use class every time? Is there any other reason to use ID? Would it be wrong to use only classes? Thanks
Daniel Riches19,691 Points
Id's come in handy for other things like automated testing, styling and manipulate the element or traversing the DOM with it. If trying to get a specific element, it's easier when it's unique. It's also less likely to change over time. If you have have to get something that only has a class on it, then you have to use a more specific selector, using things like parent elements. The markup might get changed and then the JS, CSS, Automated Test, etc. would have to be changed as well.