Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda