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

270
Visualizações
How do I pass button as a parameter to a function?

I have a function that calls another function. My goal is to pass button as a parameter to another function.

function A(){
    var btn = $find("<%=btnX.ClientID %>");
    B(btn);
}

function B(*btn parameter here*){
//I need button here
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You sort of dont even have a issue since it should already work...

function A(){
    // var btn = $find("<%=btnX.ClientID %>");
    btn = "test" // remove this "test" line
    B(btn);
}

function B(button){
//I need button here
console.log(button)
}

A()

about 4 years ago · Juan Pablo Isaza Relatório

0

It should just work. Do you see any errors there?

function A(){
    var btn = $find("<%=btnX.ClientID %>");
    B(btn);
}

function B(button){
  // Do with that button whatever you want here. E.g.
  button.style.color = 'cyan';
}

A()

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this with any selector. It should just work

function A(){
    var btn = "#btn";
    B(btn);
}

function B(button){
  // Do with that button whatever you want here. E.g.
  var btn = document.querySelector(button);

  btn.style.backgroundColor = 'red';
  btn.style.color = 'white';
}

A();

function A(){
    var btn = "#btn1";
    B(btn);
}

function B(button){
  // Do with that button whatever you want here. E.g.
  var btn = document.querySelector(button);
  
  console.log(button);
  
  btn.style.backgroundColor = 'red';
  btn.style.color = 'white';
}

A();
<button id="btn0">click button</button>
<button id="btn1">click button</button>

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