Check if two nodes are, in fact, the same node:
The result of x will be:
More "Try it Yourself" examples below.
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.
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).
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node you want to compare the specified node with |
Return Value: | A Boolean, returns true if the two nodes are the same node, otherwise false |
---|---|
DOM Version | Core Level 3 Node Object |
Using the === operator to check if two nodes are the same node: