Element.getElementsByTagNameNS() - Web APIs 编辑
The Element.getElementsByTagNameNS()
method returns a live HTMLCollection
of elements with the given tag name belonging to the given namespace. It is similar to Document.getElementsByTagNameNS
, except that its search is restricted to descendants of the specified element.
Syntax
elements = element.getElementsByTagNameNS(namespaceURI, localName)
elements
is a liveHTMLCollection
of found elements in the order they appear in the tree.element
is the element from where the search should start. Note that only the descendants of this element are included in the search, not the node itself.namespaceURI
is the namespace URI of elements to look for (seeElement.namespaceURI
andAttr.namespaceURI
). For example, if you need to look for XHTML elements, use the XHTML namespace URI,http://www.w3.org/1999/xhtml
.localName
is either the local name of elements to look for or the special value"*"
, which matches all elements (seeElement.localName
andAttr.localName
).
Example
// check the alignment on a number of cells in a table in an XHTML document.
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
}
}
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Element.getElementsByTagNameNS()' in that specification. | Living Standard | Changed the return value from NodeList to HTMLCollection . |
Document Object Model (DOM) Level 3 Core Specification The definition of 'Element.getElementsByTagNameNS()' in that specification. | Obsolete | No change from Document Object Model (DOM) Level 2 Core Specification. |
Document Object Model (DOM) Level 2 Core Specification The definition of 'Element.getElementsByTagNameNS()' in that specification. | Obsolete | Initial definition |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论