How can you check if two DOM nodes are siblings without jquery?
<div>
   <a></a>
   <b></b>
   <c>
       <d></d>
   </c>
</div>
a and c are siblings but a and d are not.
a and a are not siblings.
How can you check if two DOM nodes are siblings without jquery?
<div>
   <a></a>
   <b></b>
   <c>
       <d></d>
   </c>
</div>
a and c are siblings but a and d are not.
a and a are not siblings.
 
    
    Just check their .parentElement property.
let isSibling = el1 !== el2 && el1.parentElement === el2.parentElement;
 
    
    Why not check parentNode (or parentElement) property?
function areSiblings(a, b) {
  return a!=b && a.parentNode == b.parentNode; 
}
 
    
    Just use .parentElement or .parentNode to determine if they share the same parent.
var a = document.querySelector('a');
var b = document.querySelector('b');
var c = document.querySelector('c');
var d = document.querySelector('d');
function areSiblings(x, y) {
  return x !== y && x.parentElement === y.parentElement;
}
function areSiblings2(x, y) {
  return x !== y && x.parentNode === y.parentNode;
}
console.log(areSiblings(a, b)); // true
console.log(areSiblings(a, c)); // true
console.log(areSiblings(a, d)); // false
console.log(areSiblings2(a, b)); // true
console.log(areSiblings2(a, c)); // true
console.log(areSiblings2(a, d)); // false<div>
   <a></a>
   <b></b>
   <c>
       <d></d>
   </c>
</div>