var classFind= $('.frame').parent().parent().parent().parent().parent();
if (classfind.hasClass(".class")) {
return true;
}
I have a class that is located according to this path^… How could I loop through the dom to automate this process with better code readability? If it does not find the .hasclass before it hits a null then simply return false.
Can’t you just replace this with…
The
closestmethods travels up the DOM tree until it finds the element that matches the selector given as its param – and then stops immediately; it will return empty collection of elements (which is still an object, hence its length should be checked) if no such element is found. And!!is the same asBoolean()call – it’s not required, but will make your function return boolean values (true/false) instead of0/1.