我想弄清楚如何在擴展其他div時關閉其他div。切換關閉其他打開的div
在這裏看看我的代碼:
$(document).ready(function() {
\t $(".faq-question").click(function() {
\t
\t \t $(this).toggleClass('open');
\t \t $(this).parent().next('.field-faq-answer').toggle();
\t });
\t
}); \t
.field-faq-answer{
\t display:none; \t
}
.faq-antwoord{
\t border-bottom: 1px solid #ccc; \t
\t margin-top:10px;
\t padding-bottom:10px;
}
.faq-antwoord p{
\t margin-bottom:0px;
\t padding-left: 10px;
border-left: 2px solid #3395d3;
\t margin-left:10px;
}
.field-faq-question-first{
\t border-top: 1px solid #ccc; \t
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="faq-container">
<div class="field-faq-question field-faq-question-first">
<h3 class="faq-question">
Titel 1
</h3>
</div>
<div class="field-faq-answer">
<div class="faq-antwoord">
<p>
TEST 1
</p>
</div>
</div>
</div>
<div class="faq-container">
<div class="field-faq-question field-faq-question-first">
<h3 class="faq-question">
Titel 2
</h3>
</div>
<div class="field-faq-answer">
<div class="faq-antwoord">
<p>
TEST 2
</p>
</div>
</div>
</div>
<div class="faq-container">
<div class="field-faq-question field-faq-question-first">
<h3 class="faq-question">
Titel 3
</h3>
</div>
<div class="field-faq-answer">
<div class="faq-antwoord">
<p>
TEST 3
</p>
</div>
</div>
</div>
現在可以點擊titel 1
和titel 2
和內容都將顯示。但我想只是想顯示1個回答並隱藏其他