Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

75
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda