XML DOM isSameNode() Method


❮ Node Object

Example

The following code fragment loads "books.xml" into xmlDoc and tests whether the two nodes are the same node:

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')[1];
    var y = xmlDoc.getElementsByTagName('book')[1];
    document.getElementById("demo").innerHTML =
    x.isSameNode(y);
}

Output:

true
Try it Yourself »

Definition and Usage

The isSameNode() method tests whether two nodes are the same node.

Tip: Use the isEqualNode() method to determine if two nodes are equal.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The isSameNode() method is supported in all major browsers.

Note: Internet Explorer 9 and earlier do not support the isSameNode() method.


Syntax

nodeObject.isSameNode(nodetocheck)

Parameters

Parameter Type Description
nodetocheck Node object Required. The node to compare with the current node

Return Value

Type Description
Boolean true if the two nodes are the same, otherwise false

Technical Details

DOM Version Core Level 3 Node Object

❮ Node Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.