Méthode isSameNode() de l'élément DOM HTML
- Page précédente isEqualNode()
- Page suivante isSupported()
- Retour au niveau supérieur Objet Elements DOM HTML
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 returns 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 |
is supported by all mainstream browsers isSameNode()
method, except for Firefox.
Remarque :Firefox version 10 has stopped supporting this method because it has been deprecated in DOM version 4. As an alternative, you should use ===
Pour comparer deux nœuds pour voir s'ils sont identiques.
Remarque :Internet Explorer 8 et les versions antérieures ne prennent pas en charge cette méthode.
- Page précédente isEqualNode()
- Page suivante isSupported()
- Retour au niveau supérieur Objet Elements DOM HTML