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?
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.
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.
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 '==='
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With