Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between node.isSameNode(node1) and node === node1 in the DOM?

var a = document.getElementById('a');
var b = document.getElementById('a');

a.isSameNode(b); // true
a === b; // true

What is the browser compatibility of each approach?

like image 354
Austin K Avatar asked Sep 15 '16 19:09

Austin K


People also ask

How can we check equality of 2 nodes in JavaScript?

isEqualNode() The isEqualNode() method of the Node interface tests whether two nodes are equal. Two nodes are equal when they have the same type, defining characteristics (for elements, this would be their ID, number of children, and so forth), its attributes match, and so on.

Is same Node Javascript?

The isSameNode() method of the Node interface is a legacy alias the for the === strict equality operator. That is, it tests whether two nodes are the same (in other words, whether they reference the same object). Note: There is no need to use isSameNode() ; instead use the === strict equality operator.


1 Answers

isSameNode was deprecated in DOM v4. Firefox dropped support in version 10. I believe other major browsers support it, for now.

The recommended approach is to use '==='

like image 73
Adam Avatar answered Sep 17 '22 15:09

Adam