Element.getElementsByTagNameNS() 方法返回在指定命名空间内带有指定名称的动态HTML元素集合(而不是快照),搜索范围限定于指定元素的后代,类似于Document.getElementsByTagNameNS


elements = element.getElementsByTagNameNS(namespaceURI, localName)
  • elements 是匹配元素的动态HTML元素集合HTMLCollection,其顺序为遍历树时匹配元素出现的先后。
  • element 是查找的起始结点,查找范围为该元素的后代,并且不包含该元素自身。
  • namespaceURI 是所要查询的元素的命名空间URL (参考 Node.namespaceURI). 举个例子,如果你想查找的是XHTML元素,你应该使用XHTML的命名空间URL,http://www.w3.org/1999/xhtml。
  • localName 是所要查询的元素的名称。其中特殊字符 "*" 代表所有元素 (参考 Node.localName).


// 检查一个XHTML文档中表格的单元格的对齐方式。
var table = document.getElementById("forecast-table");
var cells = table.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "td");

for (var i = 0; i < cells.length; i++) {
    var axis = cells[i].getAttribute("axis");
    if (axis == "year") {
        // grab the data



We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0[1] (Yes) (Yes)[2] 5.5 (Yes)[1] (Yes)[1]
getElementsByTagName("*") 1.0 (Yes) (Yes) 6.0 (Yes) (Yes)
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes)[2] (Yes) (Yes) (Yes)

[1] Initially, this method was returning a NodeList; it was then changed to reflects the spec change.

[2] The behavior of element.getElementsByTagNameNS changed between Firefox 3.5 and Firefox 3.6. In Firefox 3.5 and before, this function would automatically case-fold any queries so that a search for "foo" would match "Foo" or "foo". In Firefox 3.6 and later this function is now case-sensitive so that a query for "foo" will only match "foo" and not "Foo". For more background on this, please see the comment from Henri Sivonen about the change. You can also look at the relevant part of the standard, which states which parts of the API are case-sensitive and which parts aren't.

Prior to Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change.