Is there any alternate way of doing this?
hammertime.on('pan', function(e) {
if(e.target.classList.contains("disableEvent")) return false
if(e.target.parentElement?.classList?.contains("disableEvent")) return false
if(e.target.parentElement?.parentElement?.classList?.contains("disableEvent")) return false
move()
}
I.e., check if the e.target is inside the element with the class disableEvent.
You can call .closest() with a selector that matches the class.
hammertime.on('pan', function(e) {
if (!e.target.closest(".disableEvent")) {
move();
}
});
A foolproof way is to recursively keep checking the parents of the node;
function hasParentWithMatchingSelector (target:Node, selector:string) {
const allSubMenus : NodeListOf<Element> = document.querySelectorAll(selector)
let myArray = Array.from(allSubMenus)
return [...myArray].some(el =>
el !== target && el.contains(target)
)
}
Perks including checking other things too.