I have been exploring ways to use a
selectors for expanding and collapsing multiple divs, but haven't found an example that includes switching icons depending on the collapse/expand state.
Is there a way to modify the code below so that it allows me to expand and collapse multiple divs independently? For instance, opening one should not automatically open all others.
<!-- HTML -->
<a href="#" class="show_hide">Show</a>
<div class="slidingDiv" style="display: block;">
Check out
</div>
<!-- CSS -->
.show_hide{
background:url(http://img37.imageshack.us/img37/1127/plusminus.png) no-repeat;
padding-left:20px;
}
<!-- JS -->
$(document).ready(function(){
$(".slidingDiv").hide();
$('.show_hide').click(function(){
$(this).next(".slidingDiv").slideToggle();
var isShow = $(this).text() == 'Show';
$(this).text(isShow ? 'Hide' : 'Show').css({backgroundPosition:'0 '+ (isShow?-18:0) +'px'});
});
});