Last active
March 7, 2017 03:36
-
-
Save roboshoes/9519ccdf92333d78d9bf6ce5e2b1ffd8 to your computer and use it in GitHub Desktop.
Find attribute in node or parent.
This file contains 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
// find attribute | |
export function findInParent( node, attribute, levels = Infinity ) { | |
return node.getAttribute( attribute ) || | |
( levels > 0 ? findInParent( node.parentElement, attribute, --levels ) : null ); | |
} | |
// find anything | |
export function findInParent( node, filter, levels = Infinity ) { | |
return filter( node ) || | |
( levels > 0 ? findInParent( node.parentElement, filter, --levels ) : null ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hapticdata ... very wise Mr Data. Adjusted as suggested.