The HTML DOM Element isSameNode() method

Definition and usage

isSameNode() The method checks if two nodes are the same node.

isSameNode() The method returns true,If the two nodes are the same node, otherwise return false.

Tip:Please use isEqualNode() method To check if two nodes are equal, but not necessarily the same node.

Example

Example 1

Check if the two nodes are actually the same node:

var item1 = document.getElementById("myList1");      // An <ul> element with id="myList"
var item2 = document.getElementsByTagName("UL")[0];  // The first <ul> element in the document
var x = item1.isSameNode(item2);

Try it yourself

Example 2

Use the === operator to check if two nodes are the same node:

var item1 = document.getElementById("myList");
var item2 = document.getElementsByTagName("UL")[0];
if (item1 === item2) {
  alert("THEY ARE THE SAME!!");
}
  alert("They are not the same.");
}

Try it yourself

Syntax

node.isSameNode(node)

Parameter

Parameter Type Description
node Node object Required. The node to be compared with the specified node.

Technical details

Return value: A boolean value, returns true if two nodes are the same node, otherwise returns false.
DOM version: Core Level 3 Node Object

Browser support

The numbers in the table indicate the first browser version that fully supports this method.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported 9.0 Not supported Supported Supported

All mainstream browsers support isSameNode() method, except for Firefox.

Note:Firefox version 10 has stopped supporting this method because it has been deprecated in DOM version 4. As an alternative, you should use === To compare whether two nodes are the same.

Note:Internet Explorer 8 and earlier versions do not support this method.