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

146
Visualizações
Multiple button click animation jQuery

I am beginner so please don't make too much fun of me, but I am having issues trying to get separate buttons to react when clicked. The current code that I have written will dim the all of the buttons when I click on only one of them. The problem is that I have 4 buttons and I want them to all be independent, but I don't want to type the same code 4 times for each of them.


Here is my HTML:

  <div type="button" id="green" class="btn green">

  </div>

  <div type="button" id="red" class="btn red">

  </div>
</div>

<div class="row">

  <div type="button" id="yellow" class="btn yellow">

  </div>
  <div type="button" id="blue" class="btn blue">

  </div>

</div>

Here is my jQuery code:

let buttonDim = function(){
  $(".btn").on("click", function(){
    $(".btn").addClass("pressed");
    setTimeout(function(){
      $(".btn").removeClass("pressed");
    }, 100);
  });
}
buttonDim();

I am aware that I have probably written the code ridiculously longer than it needs to be, but I am still learning. Any help would be greatly appreciated, thank you.

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

0

Try js buttonDim() like this

 $(".btn").on("click", function(){
  var button=$(this);
   button.addClass("pressed");
   setTimeout(function()
 {
    button.removeClass('pressed');
        
 }, 2000);
});
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