要素ノードを反復処理するためにelement.childrenを使用し、テキストノードを処理するためにchildNodesを使用しました。 テキストノードと要素ノードの両方をどのように反復処理できますか?テキストノードと要素ノードを反復する
let children = this.element.children;
for (let i = 0; i < children.length; i++) {
// do something with children[i] element
}
let childrenNodes = this.element.childNodes;
for (let i = 0; i < childrenNodes.length; i++) {
if (childrenNodes[i].nodeName == "#text") {
// do something with childrenNodes[i] text node
}
}
childNodesを持つ要素にアクセスできますか?
いくつかのコード(現行のHTML/JSなど)を投稿してください。 –