Created
September 3, 2016 05:33
-
-
Save hagata/b9ceb85fd0e98400f013c8e4652731b2 to your computer and use it in GitHub Desktop.
es6 dom util functions module (export opject)
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
| /** | |
| * Utility functions for common dom operations. | |
| */ | |
| const dom = { | |
| /** | |
| * Gets closest ancestor element with matching class. | |
| * ref: http://stackoverflow.com/questions/22119673/find-the-closest-ancestor-element-that-has-a-specific-class | |
| * | |
| * @param {Node} el Root note to begin search. | |
| * @param {String} cls Class to match. | |
| * @returns {Node} Matching ancestor Node with class. | |
| */ | |
| getAncestorByClass(el, cls) { | |
| while ((el = el.parentElement) && !el.classList.contains(cls)); | |
| return el; | |
| } | |
| } | |
| export {dom} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so far, only one helper function.