Element: children プロパティ
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.
children
は読み取り専用のプロパティで、生きた HTMLCollection
で呼び出された要素の子要素をすべて返します。
Element.children
は要素のノードしか含みません。すべての子ノード、例えばテキストやコメントノードなどを取得するには、 Node.childNodes
を使用してください。
値
生きた HTMLCollection
で、 node
の子の DOM 要素の順序付きコレクションを返します。コレクションの item()
メソッドか、 JavaScript の配列スタイルの記法を使って、コレクション内の個々の子ノードにアクセスすることができます。
ノードが子要素を持たない場合、 children
は要素を含まず、length
は 0
です。
例
js
const myElement = document.getElementById("foo");
for (const child of myElement.children) {
console.log(child.tagName);
}
仕様書
Specification |
---|
DOM # ref-for-dom-parentnode-children① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
children |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.