Skip to content

Instantly share code, notes, and snippets.

@VictorQueiroz
Created November 16, 2016 23:41
Show Gist options
  • Select an option

  • Save VictorQueiroz/dd313f1b5a4679a0efd642107c9c9d99 to your computer and use it in GitHub Desktop.

Select an option

Save VictorQueiroz/dd313f1b5a4679a0efd642107c9c9d99 to your computer and use it in GitHub Desktop.
Simple recursive function to get the next DOM node matching a selector
function getNextNode(current, selector){
if(current && current.nodeType != Node.ELEMENT_NODE && current.nextSibling) {
return getNextNode(current.nextSibling, selector);
}
if(current && current.nextSibling && !current.matches(selector)){
return getNextNode(current.nextSibling, selector);
}
if(current.nodeType != Node.ELEMENT_NODE) {
return null;
}
return current && current.matches(selector);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment