javascript node has parent with class
/**
* If the element/node ('child') has the class 'classname' => return true
* Else: call the function again with parent until parent with class is found or no parent is left
*/
function hasParentClass(child, classname){
if(child.className.split(' ').indexOf(classname) >= 0) return true;
try{
//Throws TypeError if child doesn't have parent any more
return child.parentNode && hasParentClass(child.parentNode, classname);
}catch(TypeError){
return false;
}
}
Also in JavaScript:
- full screen a div
- javascript iterate over json
- what does componentDidCatch do in react
- mm dd yyyy how to get date in this format in javascript
- nodejs include json file
- angular coding examples
- javascript get selected option
- service worker js example
- how to write to a json file in javascript
- javascript login system
- redirect to page in javascript
- js check if date is future
- node save json to file
- Write a JavaScript function called “GCD()” that takes the values from “Number 1“and “Number 2” then calculate the greatest common divisor of the two numbers and show the result as alert.
- connect react native app to local api macos
- javascript write to text file stack overflow
- react native debug apk
- javascript change class of item
- mv multiple directories
- upload photos cypress
- datetime to date javascript
- define a media query in styled components
- angular access service in console
- unique values in array javascript