accordian + and - symbol help
<script type='text/javascript'>
$(document).ready(function() {
$('div.S开发者_Go百科yb> div').hide();
$('div.Syb> h4').click(function() {
var span = $(this).children('span:first').attr('class');
// span.text(span.text()=='+'?'-':'+');
span = (span == 'plus')?'minus':'plus';
$(this).children('span:first').attr('class',span);
$(this).next('div').slideToggle('fast')
.siblings('div:visible').attr('css','plus').slideUp('fast');
// $(this).siblings('div.Syb>h4 >span:first').attr('css','plus');
});
});
</script>
when ever the div gets closed in need to put + symbol back...which i am not able to do ..any help on this?
<div class="Syb">
<h4><span class='plus'></span>Title 1</h4>
<div>Lorem...</div>
<h4><span class='plus'></span>Title 2</h4>
<div>Ipsum...</div>
<h4><span class='plus'></span>Title 3</h4>
<div>Dolor...</div>
</div>
is my html
You can use .toggleClass()
, like this:
$(this).children('span:first').toggleClass('plus minus');
I can't be sure that the selector to find the <span>
is right without the HTML though. Since the element has one class or the other, a toggle of both effectively swaps them, short and simple :)
精彩评论