I found this code (jQuery):
$('.toggle').click(function() { $('.container').eq($(this).index()).toggle('fast'); });
This is my HTML:
<h4 class="toggle">Title1</h4> <h4 class="toggle">Title2</h4> <h4 class="toggle">Title3</h4> <div class="container">Content1</div> <div class="container">Content2</div> <div class="container">Content3</div>
CSS
.container { display: none; }
I can switch what I want with him.
Problem
When I click on the toggle class, I want to close all open container classes, but not the current container class (because it needs to be switched).
The current container class should switch. This means that all elements can be closed, BUT ONLY ONE can be opened at the same time.
I tried to just hide jQuery before the script, but this makes it impossible to close the container class (because when switching hide show equally).
Guess the code to hide all .container except this
source share