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

190
Views
Making a dropdown button turn (and stay) green in JavaScript

So, I'm new to coding, and I have been struggling to make a dropdown button turn green when you click the main button "Pronto". I've followed some steps from similar questions here, but they didn't work for me. No effects at all. Can you give me some insights?

HTML:

<div class="btn-group">
                <button class="btn btn-default">Pronto</button>
                <button type="button" class="btn btn-default dropdown-toggle dropdown-icon" data-toggle="dropdown" aria-expanded="false">
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <div class="dropdown-menu" role="menu" style="">
                  <a class="dropdown-item" href="#">Pronto</a>
                  <div class="dropdown-divider"></div>
                  <a class="dropdown-item" href="#">Item Não Disponível</a>
                  
                </div>

JavaScript:

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl)
})
var registerAccountButton = document.getElementById('registerAccountButton');
var registerAccountModal = new bootstrap.Modal(document.getElementById('registerAccountModal'), {
    keyboard: false
})
registerAccountButton.addEventListener('click', function () {
    registerAccountModal.toggle();
})
$('input[type="button"]').click(function(){
  $('input[type="button"].green').removeClass('green')
      $(this).addClass('green');
});

CSS:

    .green {
  background-color: greenyellow;
}

You can even see I tried creating a class and calling it, but didn't work. What am I missing?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your problem is the following code

$('input[type="button"]').click(function(){
    $('input[type="button"].green').removeClass('green')
    $(this).addClass('green');
});

You have created your buttons using the <button> in html, but in js you are referencing them using <input type="button"> which is not present & hence is ignored by jQuery.

Your code should be something like follows, to make the dropdown button green, when the Pronto button is clicked:

$('#prontoButton').on('click', function(evt) {
    $('.dropdownButton').addClass('green');
});

 
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!