Zwijanie zawartosci diva po ponownym kliknieciu na tabs

0

Jestem bardzo, bardzo zielona w temacie i przyznam, ze jestem troche z siebie dumna, ze udalo mi sie dostsowac znaleziony gdzies w sieci kod i tak go wstawic ze dziala.
Chodzilo o zrobienie 2 buttonow, ktore zachowuja sie jak tabs. Czyli po kliknieciu na button1 pojawia sie niewidocznyd odtad div1 a po kliknieciu na button2 pojawia sie div2

Problem polega na tym, ze od kilku dni probuje dodac takie zahcowanie, aby po ponownym kliknieciu na button, zeby zniknal ten div, ktory sie pojawil po kliknieciu na ten buton.

Za Chiny nie moge tego uzyskac. Po prostu chce aby po kliknieciun nr 2 zniknela klasa active, ktora poajwial sie "na buttonie" dzieki kliknieciu nr 1

<script type="text/javascript">
function openCity(evt, cityName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
</script>
4

Rzuć okiem na te dwa wątki:
Jak zmienić zawartość elementu za pomocą dwóch przycisków
Skrypt który podmienia cały kontener za pomocą dwóch przycisków

Nie jest to wprawdzie wprost odpowiedź na Twoje pytanie, ale temat jest dość podobny, może okaże się przydatny i pokieruje Cię w dobrą stronę :)

1
// Show the current tab, and add an "active" class to the button that opened the tab (if current tabs isn't active)
if (!evt.currentTarget.classList.contains("active")) {
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1