Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Book said don't use CSS IDs, use class instead but what about when Javascript? Reply To: Book said don't use CSS IDs, use class instead but what about when Javascript?

#182326
Senff
Participant

The book (which book?) probably meant that it’s OK to give IDs to elements, and to target them with JavaScript, but to not use IDs for styling. In other words, avoid calling any ID in your CSS file because of their high specificity weight.

Other than that, the use of IDs are fine, and it’s OK to call them in your JavaScript files because specificity is not an issue there.