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

122
Visualizações
Add active class to button when start typing in input

I have this code and I want to add the active class to the (withdraw-btn) button when I start typing in input and remove it again if I removed the text that I entered in input (when input is empty).

The code is running fine, but the problem is: that the active class is not added when I start typing in input so I must click outside that input.

I want to add an active class just start typing and remove it just delete the text in the input.

** Sorry For the bad language

HTML

<div class="row">
   <div class="col-12 col-md-6">
      <div class="withdrawal-amount">
         <p>Withdrawal Amount (Minimum required: $10)</p>
         <input type="text" placeholder="$10" class="withdrawal-amount-input">
      </div>
   </div> 
   <div class="col-12 col-sm-6 col-md-3">
      <div class="withdraw-btn-upper">
         <a href="#" class="withdraw-btn">Withdraw</a>
      </div>
   </div>
</div>
                        

Javascript

function addActiveclass() {
    $(".withdrawal-amount-input").on("change", function(){
        if($(this).val() == "")
            $(".withdraw-btn").removeClass('active');
        else
            $(".withdraw-btn").addClass('active');
    });
    
}
addActiveclass();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Listen for the input event instead:

function addActiveclass() {
    $(".withdrawal-amount-input").on("input", function(){
        if($(this).val() == "")
            $(".withdraw-btn").removeClass('active');
        else
            $(".withdraw-btn").addClass('active');
    });
    
}
addActiveclass();
.active{
  background-color: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
   <div class="col-12 col-md-6">
      <div class="withdrawal-amount">
         <p>Withdrawal Amount (Minimum required: $10)</p>
         <input type="text" placeholder="$10" class="withdrawal-amount-input">
      </div>
   </div> 
   <div class="col-12 col-sm-6 col-md-3">
      <div class="withdraw-btn-upper">
         <a href="#" class="withdraw-btn">Withdraw</a>
      </div>
   </div>
</div>

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