I am making an accordion of Div’s here is the code:
$('.answer').hide();
$('.question').click (function(){
$('.answer').slideUp();
$('#question'+$(this).attr('target')).slideDown('slow');
})
It is working fine, but I want it so when I click again on same question it closes.
Here is the HTML I used :
<h1 class="question" target="1">Some Question</h1>
<p id="question1" class="answer">Some Answer</p>
<h1 class="question" target="2">Another question</h1>
<p id="question2" class="answer">Another answer</p>
Thanks in advance
please look the code here : http://jsfiddle.net/FMLhc/
This works:
http://jsfiddle.net/FMLhc/15/
Basically, just check the state of the toggle, and do what you need to do.