XML DOM appendChild()メソッド
Node オブジェクト
定義と使い方
appendChild() メソッドは、新しい子ノードをノードの子ノードリストの末尾に追加します。
このメソッドは、新しい子ノードを返します。
構文
appendChild(newchild)
| 引数 | 説明 |
|---|---|
| newchild | 追加するノード。 |
例
以下のコードスニペットはloadXMLDoc()"" を xmlDoc に読み込み、ノード(<edition>)を作成し、それを最初の <book> ノードの最後の子ノードの後に追加します:
例
xmlDoc=loadXMLDoc("books.xml");
newel=xmlDoc.createElement("edition");
x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);
document.write(x.getElementsByTagName("edition")[0].nodeName);
newel=xmlDoc.createElement("edition");
x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);
document.write(x.getElementsByTagName("edition")[0].nodeName);
出力:
edition
試してみる »
試してみる
Node オブジェクト その他の拡張