Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js is boolean 
Javascript :: javascript after 2 months date find 
Javascript :: vue cors 
Javascript :: generate random string react 
Javascript :: javascript how to sort alphabetically 
Javascript :: javascript convert timestamp to formatted date 
Javascript :: jquery set textbox value 
Javascript :: jq examples 
Javascript :: filter by keyname javascript 
Javascript :: async constructor javascript 
Javascript :: jquery remove css 
Javascript :: settimeout js for loop 
Javascript :: export data to excel using react js 
Javascript :: react native images 
Javascript :: anime js link 
Javascript :: get query string javascript nodejs 
Javascript :: get the most recent records in mongoose 
Javascript :: jquery sibling 
Javascript :: column width table react 
Javascript :: react tostify 
Javascript :: react prevent component from update once mounted 
Javascript :: antd datepicker set min max 
Javascript :: express server 
Javascript :: settimeout function es6 
Javascript :: (Unauthorized) not authorized on admin to execute command 
Javascript :: draw on canvas from video element js 
Javascript :: how to randomize an array 
Javascript :: disabled radio button 
Javascript :: upload preview image jquery 
Javascript :: react pass props to child 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =