I\'m really struggling to see how to do this. I want to check if a class exsits somewhere in one of the parent elements of an element.
I don\'t want to use any libra
You'll have to do it recursively :
// 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);
}
Demonstration (open the console to see true
)