THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM isSameNode() Method

Element Object Reference Element Object

Example

Check if two nodes are, in fact, 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);

The result of x will be:

true
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

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

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

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


Browser Support

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

Method
isSameNode() Yes 9.0 Not supported Yes Yes

Note: Firefox stopped supporting this method as of version 10, because the method has been deprecated in the DOM version 4. Instead, you should use === to compare if two nodes are the same (See "More Examples" below).


Syntax

node.isSameNode(node)

Parameter Values

Parameter Type Description
node Node object Required. The node you want to compare the specified node with

Technical Details

Return Value: A Boolean, returns true if the two nodes are the same node, otherwise false
DOM Version Core Level 3 Node Object

Examples

More Examples

Example

Using 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!!");
} else {
    alert("They are not the same.");
}
Try it Yourself »

Element Object Reference Element Object