Reputation: 653
I'm trying to have a collapsible list of elements, where only one can be seen at any given time.
I set it up like:
<div class="grid_12" id="menu_container">
<div class="grid_12 title" style="background-color:pink;">
Book 1
</div>
<div class="grid_12 row" style="background-color:white;">
Chapter 1
<div class="grid_12 details">Lorem lipsum sin dolor chapter 1</div>
</div>
<div class="grid_12 row" style="background-color:white;">
Chapter 2
<div class="grid_12 details">Lorem lipsum sin dolor chapter 2</div>
</div>
</div>
I tried a lot of things with my javascript function, and ended up lost and confused... Can anyone please help me out on this?
$(".row").click(function(e){
$(".current").slideUp(function(){
$(".current").hide();
$(".current").removeClass("current");
});
$(this).children("div.details").addClass("current");
$(this).children("div.details").slideDown();
});
Thanks in advance! S.
Upvotes: 1
Views: 156
Reputation: 144729
Something like this?
$(".row").click(function(e){
var $e = $(this).children();
if ($e.hasClass('current')) return;
$(".current").slideUp(function(){
$(this).removeClass("current");
});
$e.addClass("current").slideDown();
});
Upvotes: 1