Element: getElementsByTagNameNS() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Element.getElementsByTagNameNS()
メソッドは、指定された名前空間に属する、指定されたタグ名を持つ要素の HTMLCollection
をライブで返します。これは Document.getElementsByTagNameNS
に似ていますが、検索対象が指定された要素の子孫に限定される点が異なります。
構文
js
getElementsByTagNameNS(namespaceURI, localName)
引数
namespaceURI
は検索する要素の名前空間 URI です(Element.namespaceURI
およびAttr.namespaceURI
を参照してください)。例えば、XHTML 要素を検索する場合は、XHTML の名前空間 URI であるhttp://www.w3.org/1999/xhtml
を使用してください。localName
は検索する要素のローカル名、またはすべての要素に一致する特殊な値"*"
です(Element.localName
およびAttr.localName
を参照)。
返値
生きた HTMLCollection
で、ツリー内で見つかった要素を出現順に保持します。
例
js
// XHTML 文書の table の多くのセルの配列をチェック。
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") {
// データを取得
}
}
仕様書
Specification |
---|
DOM # dom-element-getelementsbytagnamens |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getElementsByTagNameNS | ||||||||||||
getElementsByTagNameNS(namespaceURI, "*") |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.