Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!