Skip to content

Instantly share code, notes, and snippets.

@lirongfei123
Created September 20, 2016 11:40
Show Gist options
  • Save lirongfei123/567a616fd56273c16640e2837333afa0 to your computer and use it in GitHub Desktop.
Save lirongfei123/567a616fd56273c16640e2837333afa0 to your computer and use it in GitHub Desktop.
// returns true if the element or one of its parents has the class classname
function hasSomeParentTheClass(element, classname) {
if (element.className.split(' ').indexOf(classname)>=0) return true;
return element.parentNode && hasSomeParentTheClass(element.parentNode, classname);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment