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
December 13, 2011 at 1:11 pm
#92615
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.