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

74
Views
How to toggle Bootstrap 3 classes?

I have this halfway working and have two columns. One column holds photo listings col-md-8 and the other shows a map col-md-4. My goal is to toggle the map and show the listings column taking up all 12 columns. Right now I have only figured out how to hide the map and expand the listings column but now it needs to show back. I also need to switch the button text show/hide based on toggled state. Any help appreciated.

Here is what I figured out so far.

$("#btn").click(function(e) {
 e.preventDefault();
 $('#map').hide();
 $('.expand-column').removeClass('col-md-8');
 $('.expand-column').addClass('col-md-12');
    });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can replace the current methods with toggle methods and make what you currently have work both ways

$("#btn").click(function(e) {
     e.preventDefault();
     $('#map').toggle();
     $('.expand-column').toggleClass('col-md-8 col-md-12'); 
});

I'll leave it to you to come up with a variable or another class to keep track of the current state with and use that to determine the text

about 4 years ago · Juan Pablo Isaza Report

0

After implementing charlietfl answer, here is what I came up with for handling the current state of the toggling text.

$("#btn").click(function(e) {
 e.preventDefault();
 if($(this).text()=="hide map") {
    $(this).text("show map");
 } else {
    $(this).text("hide map");
 }
 $('#map').toggle();
 $('.expand-column').toggleClass('col-md-8 col-md-12'); 
 $('.constrain-photos').toggleClass('col-lg-3 col-lg-2');
 return false;
});
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!