Skip to content

Instantly share code, notes, and snippets.

@hagata
Created September 3, 2016 05:33
Show Gist options
  • Select an option

  • Save hagata/b9ceb85fd0e98400f013c8e4652731b2 to your computer and use it in GitHub Desktop.

Select an option

Save hagata/b9ceb85fd0e98400f013c8e4652731b2 to your computer and use it in GitHub Desktop.
es6 dom util functions module (export opject)
/**
* 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}
@hagata
Copy link
Author

hagata commented Sep 3, 2016

so far, only one helper function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment