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

218
Visualizações
Passing a function with an argument to addEventListener automatically runs the function onload

I'm having trouble passing a function with an arugment to an eventListener. Here's what I'm doing:

document.getElementById('Sec1_BTN1').addEventListener('click', copyS1(1));

this is the function it's referring to:

function copyS1(elemIDNum) {
    var letter_to_copy = document.getElementById('textarea-S1-' + elemIDNum);
    letter_to_copy.select();
    navigator.clipboard.writeText(letter_to_copy.value);
};

It runs the function upon load, but does not run when I click on the button that the eventListener is attached to. Any ideas of what I can do to fix it? I did some searching, but could've figure it out.

about 4 years ago · Juan Pablo Isaza
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