Element:getElementsByTagNameNS() 方法
Element.getElementsByTagNameNS()
方法返回一个对给定命名空间中具有给定标签名称的元素的实时 HTMLCollection
。它与 Document.getElementsByTagNameNS
类似,但其搜索仅限于指定元素的后代。
语法
js
getElementsByTagNameNS(namespaceURI, localName)
参数
namespaceURI
-
要查找的元素的命名空间 URI(请参阅
Element.namespaceURI
和Attr.namespaceURI
)。例如,如果您需要查找 XHTML 元素,请使用 XHTML 命名空间 URIhttp://www.w3.org/1999/xhtml
。 localName
-
要查找的元素的本地名称,或者特殊值
"*"
,它匹配所有元素(请参阅Element.localName
和Attr.localName
)。
返回值
一个动态的 HTMLCollection
,包含了按在树中出现的顺序排列的已找到的元素。
示例
js
// Check the alignment on a number of cells in a table in an XHTML document.
const table = document.getElementById("forecast-table");
const cells = table.getElementsByTagNameNS(
"http://www.w3.org/1999/xhtml",
"td",
);
for (const cell of cells) {
const axis = cell.getAttribute("axis");
if (axis === "year") {
// Grab the data
}
}
规范
规范 |
---|
DOM # dom-element-getelementsbytagnamens |
浏览器兼容性
加载中…