Last Updated: February 25, 2016
·
425
· searsaw

DOM Navigation without jQuery

Text nodes can be painful when navigating the DOM. Let's disregard them without jQuery!

function getNextSibling(el) {
    el = el.nextSibling;
    while (el) {
    if (el.nodeType !== 3) {
        return el;
    }
    el = el.nextSibling;
    }
}

This will let you get the next sibling of the element you grabbed without worrying about text nodes.