.allopenerスパンが押されたときに、質問の下にあるすべての回答を展開する方法を見つけようとしています。現在、ユーザーは各回答を個別に展開できますが、一度にすべてを展開することはできません。ヒントをいただければ幸いです。1ページに多くのアイテムがあります。
allopener spanボタンは、このアイテムの残りの非表示の.textクラスを開き、誰かがそれぞれを個別に展開をクリックしたかのように、質問への回答を表示します。初めて押すと、回答の一部、全部、またはまったく展開されていない可能性があることに注意してください。また、もう一度押すと、すべての回答が非表示になります。また、もう一度押すと、すべての回答が展開されます。繰り返しますが、すべて隠されています。
を押すと、それに応じて各回答の展開ボタンの背景も変化します。つまり、個々の展開ボタンのクラス.highlightcを切り替えているかのように、オンとオフを切り替えます。
jquery:
$('.answeropener').click(function() {
$(this).next().toggle(); //unhide/hide the sibling text answer
$(this).toggleClass("highlightc"); //alternate the background of this button
return false;
});
$('.allopener').click(function() {
$(this).toggleClass("highlighti"); //toggles background of button
$(this).
$(this).
return false;
});
css:
.highlighti {background: #FFFFFF;}
.highlightc {border-right:1px solid #DCDCDC;}
.text {display:none;}
html:
<div class="item" id="question1">
<div class="tophead">How do you skin a cat?</div>
<div class="bottomhead">by Gerald, 1 hour ago <span class="allopener">open/close</span> <span>all answers below<span>
<div class="answers">
<div class="answer"><div class="answernumber">1</div><div class="answerhead">answer by Harold <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">this is my answer</div></div></div>
<div class="answer"><div class="answernumber">2</div><div class="answerhead">answer by Jesse <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">this is my answer too</div></div></div>
<div class="answer"><div class="answernumber">3</div><div class="answerhead">answer by Seth <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">I don't know</div></div></div>
</div> <!--answers-->
</div> <!--bottomhead-->
</div> <!--item-->