1/**
2 * If the element/node ('child') has the class 'classname' => return true
3 * Else: call the function again with parent until parent with class is found or no parent is left
4*/
5function hasParentClass(child, classname){
6 if(child.className.split(' ').indexOf(classname) >= 0) return true;
7 try{
8 //Throws TypeError if child doesn't have parent any more
9 return child.parentNode && hasParentClass(child.parentNode, classname);
10 }catch(TypeError){
11 return false;
12 }
13}