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

196
Views
How to toggle Bootstrap buttons one at a time

Hi I have this piece of code that allows me to toggle one at a time. However there is a bug where if I click the first button out of the two it does what I want but, when the second button is clicked I can't untoggle the first button. However if I select the second button first and then select the first button the second button gets untoggled and the first one is now active.

<button type="button" id="b1"class="btn btn-primary " data-bs-toggle="button" value="Toronto" onClick="GetWeatherInfo()">Toronto Oakvile

  var btn1 = document.getElementById('b1');
  var btn2 = document.getElementById('b2');
  var selectedCity;

  if (btn1.classList.contains('active')){
    btn2.classList.remove("active");
    var selectedCity=document.getElementById("b1").value;
  }
  else if(btn2.classList.contains('active')){
    btn1.classList.remove("active");
    var selectedCity=document.getElementById("b2").value;
  }
about 4 years ago · Santiago Gelvez
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!