Forums

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

Home Forums JavaScript Javascript: Selecting an elment with a class within an element with an id Re: Javascript: Selecting an elment with a class within an element with an id

#92615
Senff
Participant

You’ll have to use an index number, to indicate which one of the found elements with that class you want to target. This will select the first one:

document.getElementById('theId').getElementsByClassName('theClass')[0];

I’ve never figured out how to select all classes with getElementsByClassName, so that’s why jQuery is so great.