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?
September 8, 2014 at 6:26 pm
#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).