interactiveRob
1/18/2019 - 8:03 PM

Plain JS get siblings ES6 Method

Plain JS get siblings ES6 Method

  getSiblings(elem) {
    var siblings = [];
    var sibling = elem.parentNode.firstChild;
    for (; sibling; sibling = sibling.nextSibling) {
        if (sibling.nodeType !== 1 || sibling === elem) continue;
        siblings.push(sibling);
    }
    return siblings;
}