私はDivのアコーディオンを作っています。ここにコードがあります:
$('.answer').hide();
$('.question').click (function(){
$('.answer').slideUp();
$('#question'+$(this).attr('target')).slideDown('slow');
})
正常に動作していますが、同じ質問をもう一度クリックすると閉じます。
これが私が使用したHTMLです:
<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>
前もって感謝します
こちらのコードをご覧ください:http://jsfiddle.net/FMLhc/