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?

#182297
__
Participant

Take the time to do some research and find out what functions javascript provides for this sort of thing. MDN is a good resource for this. There is no such thing as document.getElementByClass, but there is document.getElementsByClassName, which does what you describe.*

* nb; in contrast to getElementById, getElementsByClassName returns a list of elements (since there might be any number of elements with the specified class name —hence the plural form).