Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda