Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
How to check if an element is present in the event bubbling propagation tree?

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.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can call .closest() with a selector that matches the class.

hammertime.on('pan', function(e) {
  if (!e.target.closest(".disableEvent")) {
    move();
  }
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda