एक्सएमएल डोम तुलना दस्तावेज़ स्थिति () विधि
नोड वस्तु
उदाहरण
निम्नलिखित कोड खंड " books.xml " को xmlDoc में लोड करता है और DOM पदानुक्रम में दो नोड्स (पहला और तीसरा <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 x =
xmlDoc.getElementsByTagName('book')[0];
var y =
xmlDoc.getElementsByTagName('book')[2];
document.getElementById("demo").innerHTML =
x.compareDocumentPosition(y);
}
उपरोक्त कोड का आउटपुट होगा:
4
अधिकांश ब्राउज़र, खाली सफेद-रिक्त स्थान या नई लाइनों को टेक्स्ट नोड्स के रूप में मानेंगे, IE 9 और इससे पहले का नहीं होगा। तो, ऊपर के उदाहरण में, अधिकांश ब्राउज़र 4 आउटपुट करेंगे, जबकि IE 9 और पहले वाले 2 आउटपुट देंगे।
परिभाषा और उपयोग
ComparDocumentPosition () विधि DOM पदानुक्रम (दस्तावेज़) में दो नोड्स के प्लेसमेंट की तुलना करती है।
ब्राउज़र समर्थन
ComparDocumentPosition () विधि सभी प्रमुख ब्राउज़रों में समर्थित है।
नोट: Internet Explorer 9 और इससे पहले के संस्करण इस पद्धति का समर्थन नहीं करते हैं।
वाक्य - विन्यास
nodeObject.compareDocumentPosition(node)
मापदंडों
Parameter | Type | Description |
---|---|---|
node | Node object | Required. Specifies the node to compare with the current node |
प्रतिलाभ की मात्रा
Type | Description |
---|---|
Number | A Number representing where the two nodes are positioned compared to each other. The possible return values
are:
1 - No relationship, the two nodes do not belong to the same document. 2 - The specified node precedes the current node. 4 - The specified node follows the current node. 8 - The specified node contains the current node. 16 - The specified node is contained by the current node. 32 - The specified and the current node have no common container node or the two nodes are different attributes of the same node. Note: The return value could also be a combination of values. E.g. a return value of 20 means that the specified node is contained by the current node (16) AND the specified node follows the current node (4). |
टेक्निकल डिटेल
डोम संस्करण | कोर स्तर 3 नोड वस्तु |
---|
नोड वस्तु