DHTML Methods
DOM Level 1 Specification.
Returns a list of all descendant elements that match the supplied name.
objNodeList = object.getElementsByTagName ( tagName )
tagName |
String specifying the name of the element to find. The string "*" matches all descendant elements of this element. |
Returns a collection ( NodeList object ) containing all elements that match the supplied name.
Elements appear in the order encountered in a preorder traversal of this element’s tree.
Note that a NodeList object is returned even if there are no matches. In such a case, the length of the list will be set to zero.
The DOM NodeList object is live and immediately reflects changes to the nodes that appear in the list.
The following example shows use of the getElementsByTagName method to create a NodeList of all level 5 headings ( H5 elements ) in this document, and displays each object’s nodeTtype and nodeValue in sequence:
function getHeaders ( ) {
var childs, tags = document.getElementsByTagName ( 'h5' );
if ( tags.length != 0 )
for ( t = 0; t < tags.length; t++ ) {
childs = tags [ t ] .childNodes;
for ( c = 0; c < childs.length; c++ )
alert ( tags [ t ] .tagName + ' ' + t + ' Child ' + c +
'\nnodeType " + childs [ c ] .nodeType +
'\nnodeValue " + childs [ c ] .nodeValue )
}
}
Show me
getElementById