एक्सएमएल डोम डालने से पहले () विधि
नोड वस्तु
उदाहरण
निम्नलिखित कोड खंड " books.xml " लोड करता है, एक नया <book> नोड बनाता है और इसे अंतिम <book> नोड से पहले सम्मिलित करता है:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var newNode =
xmlDoc.createElement("book");
var x =
xmlDoc.documentElement;
var y =
xmlDoc.getElementsByTagName("book");
document.getElementById("demo").innerHTML =
"Book
elements before: " + y.length + "<br>";
x.insertBefore(newNode, y[3]);
document.getElementById("demo").innerHTML
+=
"Book elements after: " + y.length;
}
उपरोक्त कोड का आउटपुट होगा:
Book elements before: 4
Book elements after: 5
परिभाषा और उपयोग
सम्मिलित करें () विधि वर्तमान नोड के निर्दिष्ट चाइल्ड नोड से पहले एक नया चाइल्ड नोड सम्मिलित करती है।
नोट: यदि नया बच्चा पहले से ही पेड़ में है, तो उसे पहले हटा दिया जाता है।
ब्राउज़र समर्थन
सम्मिलित करें () विधि सभी प्रमुख ब्राउज़रों में समर्थित है।
वाक्य - विन्यास
nodeObject.insertBefore(newchild,existingnode)
मापदंडों
Parameter | Type | Description |
---|---|---|
newchild | Node object | Required. The new child node to insert |
existingnode | Node object | Required. The node to insert the new child node before. If existingnode is null, insert newchild at the end of the list of children |
प्रतिलाभ की मात्रा
Type | Description |
---|---|
Node object | The inserted node |
टेक्निकल डिटेल
डोम संस्करण | कोर स्तर 1 नोड वस्तु। डोम स्तर 3 . में संशोधित |
---|
नोड वस्तु