Utility function for finding the first element parent with a classname class - Node.js CSS

Node.js examples for CSS:Class

Description

Utility function for finding the first element parent with a classname class

Demo Code


/**//ww w . j a  v a2 s . com
 * Utility function for finding the first ele element parent with a classname class
 * @param ele
 * @param classname
 * @return - the parent element or null
 */
function findParentByClassName(ele, classname) {
  var par = ele.parentElement;
  while (par != null) {
    if (hasClass(par,classname)) {
      break;
    }
    par = par.parentElement;
  }
  return par;
}

Related Tutorials