I'm trying to use the getElementsByTagName("a") method to get all the elements under a specific tag.
However, I don't want every anchor tag. How would I narrow it so I only select all the anchor tags under the the ul tag for "someListClass" name?
<ul class="someListClass"> <li><a href... /></li>... </ul>
Give your ul an id and then use
<ul id="ulid" class="someListClass"> <li><a href... /></li>... </ul> document.getElementById ( "ulid" ).getElementsByTagName ( "a" );
elements = element.getElementsByTagName(tagName);
elements is a live NodeList of found elements in the order they appear in the subtree.
element is the element from where the search should start. Note that only the descendants of this element are included in the search, but not the element itself.
tagName is the qualified name to look for. The special string "*" represents all elements. For compatibility with XHTML, lower-case should be used.