HTML DOM Element isSameNode() metoden
- Föregående sida isEqualNode()
- Nästa sida isSupported()
- Åter till föregående nivå HTML DOM Elements objekt
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
.
Hint: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);
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."); }
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 |
Support | 9.0 | Not supported | Support | Support |
All mainstream browsers support isSameNode()
method, except for Firefox.
Kommentar:Firefox version 10 stops supporting this method because it has been deprecated in DOM version 4. As an alternative, you should use ===
För att jämföra om två noder är identiska.
Kommentar:Internet Explorer 8 och tidigare versioner stöder inte denna metod.
- Föregående sida isEqualNode()
- Nästa sida isSupported()
- Åter till föregående nivå HTML DOM Elements objekt