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

142
Visualizações
Passing The Right Series Of Arguments

In one HTML page, I have 2 onclick events like this :

onclick="clear_input('button1', 'hello1','world1');"
onclick="clear_input('button2','hello2','world2');"
 

In a JS file I have this :

function clear_input(a, b, c) {

var text = document.getElementById(b);

var button = document.getElementById(a);

…

}

It all works. Now I want to get rid of the inline JS and implement in the JS file an addEventListener that could process any one of the 2 onclick events. How do I pass the right series of arguments ?

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

0

If it's just two, it's probably not worth effort to create some generic solution. Just add each call individually.

document.getElementById('whatever1').addEventListener('click', function(){
    clear_input('button1', 'hello1', 'world1');
});
document.getElementById('whatever2').addEventListener('click', function(){
    clear_input('button2', 'hello2', 'world2');
});

If you need a more generic solution you'll need to explain more about the situation, like why the arguments are 'button1', 'hello1', 'world1' to start with.

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