HTML DOM isSameNode() Method
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);
Try it Yourself »
More "Try it Yourself" examples below.
Description
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 |
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 »
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.