Created
November 16, 2016 23:41
-
-
Save VictorQueiroz/dd313f1b5a4679a0efd642107c9c9d99 to your computer and use it in GitHub Desktop.
Simple recursive function to get the next DOM node matching a selector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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