Описание тега getelementsbytagname

A native HTML DOM Element method used to get all elements with the specified tag name.

Description

getElementsByTagName is a native HTML DOM Element method used to get all elements with the specified tag name.

The returned list is live, meaning that it updates itself with the DOM tree automatically. Consequently, there is no need to call several times element.getElementsByTagName with the same element and arguments.

Syntax

elements = element.getElementsByTagName(tagName);

where,

  • elements is a live NodeList (but see the note below) of found elements in the order they appear in the subtree. If no elements were found, the NodeList is empty.
  • 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.

Specifications & References

  1. W3C Specification
  2. getElementsByTagName - MDN Link