function findAncestor (el, cls) {
while ((el = el.parentElement) && !el.classList.contains(cls));
return el;
}
document.querySelector(".product__shopcard-btn").closest(".product"); // <div class="product"></div>
let element = document.querySelector(".product__shopcard-btn");
while (!element.classList.contains("product")) {
element = element.parentElement;
if (!element) {
break;
}
}
const find = (node, className) => {
while (node) {
if (node.classList.contains(className)) {
return node;
} else {
node = node.parentElement;
}
}
return null;
}