XML DOM appendChild() method
Definition and Usage
The appendChild() method adds a node after the last child node of the specified element node.
This method returns the new child node.
Syntax:
appendChild(node)
Parameter | Description |
---|---|
node | Required. The node to be appended. |
Example
In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().
The following code snippet creates and appends a node to the first <book> element, and then outputs all child nodes of the first <book> element:
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++)
{
newel=xmlDoc.createElement('edition');
newtext=xmlDoc.createTextNode('First');
newel.appendChild(newtext);
x[i].appendChild(newel);
}
//Output all titles and editions
y=xmlDoc.getElementsByTagName("title");
z=xmlDoc.getElementsByTagName("edition");
for (i=0;i<y.length;i++)
{
document.write(y[i].childNodes[0].nodeValue);
document.write(" - Edition: ");
document.write(z[i].childNodes[0].nodeValue);
document.write("<br />");
}
အခြေခံ အပိုင်း အားဖြင့် အစီအစဉ်
Everyday Italian - Edition: First Harry Potter - Edition: First XQuery Kick Start - Edition: First Learning XML - Edition: First
မှတ်ချက်:Internet Explorer သည် အစိတ်အစိတ် အကြား ဖြစ်ပေါ်လာသော အကြောင်းအားကွယ်ရာ အချက်အလက် ကို စွပ်စွဲခြင်း မပြုပါ၊ ထို့ကြောင်းကို Mozilla မပြုပါ။ အရေးပါသော အချက်အလက် ကို အားလုံး အစိတ်အစိတ် အားကွယ်ရာ ကို ပြုလုပ်ခြင်း မပြုပါ။
IE နှင့် Mozilla ဘရောက်တာ အကြား အမျိုးမျိုးသော အခြေအနေ အကြောင်း သိချင်လျှင် အခြေအနေ ကို ကြည့်ရန် CodeW3C.com အပြည့်အဝါအား သိရလိုပါသလဲဆိုတာ DOM ဘရောက်တာ ဒါကို ပါ