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

183
Visualizações
Is it possible to access addEventListener options object from within callback function

I want to be able to set the addEventListener to un-attach after the first event, based on a conditional related to the event.

I want something like;

var thing = document.querySelector('.thing');
thing.addEventListener('click',function(e){
  if (e.pointerType === 'mouse'){
    this.addEventListener.options.once = true;
  }
});
<a class="thing">Thing</a>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You want to use removeEventListener. You can do it like this:


function handler(event){
  if (event.pointerType === 'mouse'){
    this.addEventListener.options.once = true;
    var targetElement = event.target || event.srcElement
    targetElement.removeEventListener("click", handler);
  }
}

var thing = document.querySelector('.thing');
thing.addEventListener('click',handler);

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