HTML DOM Element erSammeNode() metode
- Forrige side isEqualNode()
- Næste side isSupported()
- Gå tilbage til forrige niveau 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 |
supported | 9.0 | not supported | supported | supported |
All mainstream browsers support isSameNode()
method, except for Firefox.
Bemærk:Firefox version 10 stops supporting this method because it has been deprecated in DOM version 4. As an alternative, you should use ===
For at sammenligne to noder for at se, om de er ens.
Bemærk:Internet Explorer 8 og tidligere versioner understøtter ikke denne metode.
- Forrige side isEqualNode()
- Næste side isSupported()
- Gå tilbage til forrige niveau HTML DOM Elements objekt