Element.getElementsByTagName

  • Revision slug: DOM/element.getElementsByTagName
  • Revision title: element.getElementsByTagName
  • Revision id: 291548
  • Created:
  • Creator: Murb
  • Is current revision? No
  • Comment declared table and cells as vars (which Internet Explorer likes better)

Revision Content

{{template.DomRef()}}

Summary

Returns a list of the descendant elements of a given name on the current element.

Syntax

elements = element.getElementsByTagName(tagName)

Parameters

  • elements is a nodeList of elements.
  • tagName is a string representing the name of the elements. The special string "*" represents all elements.

Example

// check the alignment on a number of cells in a table. 
var table = document.getElementById("forecast-table"); 
var cells = table.getElementsByTagName("td"); 
for (var i = 0; i < cells.length; i++) { 
    status = cells[i].getAttribute("status"); 
    if ( status == "open") { 
        // grab the data 
    }
}

Notes

getElementsByTagName on the element is the same as getElementsByTagName on the document, except that its search is restricted to those elements which are descendants of the current element.

Specification

DOM Level 2 Core: getElementsByTagName

{{ wiki.languages( { "fr": "fr/DOM/element.getElementsByTagName", "pl": "pl/DOM/element.getElementsByTagName" } ) }}

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary">Summary</h3>
<p>Returns a list of the descendant elements of a given name on the current element. 
</p>
<h3 name="Syntax">Syntax </h3>
<p><i>elements</i> = element.getElementsByTagName(<i>tagName</i>) 
</p>
<h3 name="Parameters">Parameters </h3>
<ul><li><code>elements</code> is a <code>nodeList</code> of elements.
</li><li><code>tagName</code> is a string representing the name of the elements.  The special string "*" represents all elements.
</li></ul>
<h3 name="Example">Example </h3>
<pre>// check the alignment on a number of cells in a table. 
var table = document.getElementById("forecast-table"); 
var cells = table.getElementsByTagName("td"); 
for (var i = 0; i &lt; cells.length; i++) { 
    status = cells[i].getAttribute("status"); 
    if ( status == "open") { 
        // grab the data 
    }
}
</pre>
<h3 name="Notes">Notes </h3>
<p><b>getElementsByTagName</b> on the element is the same as <b>getElementsByTagName</b> on the document, except that its search is restricted to those elements which are descendants of the current element. 
</p>
<h3 name="Specification">Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-A6C9094">DOM Level 2 Core: getElementsByTagName </a>
</p>{{ wiki.languages( { "fr": "fr/DOM/element.getElementsByTagName", "pl": "pl/DOM/element.getElementsByTagName" } ) }}
Revert to this revision