Having some trouble with setting up a straightforward FAQ dropdown feature. Could someone lend a hand and see what might be going wrong?
Appreciate your help!
CSS
#faqs h3 { cursor:pointer; }
#faqs h3.active { color:#d74646; }
#faqs div { height:0; overflow:hidden; position:relative; }
#faqs div p { padding:0; margin-bottom:15px; }
JavaScript:
$(document).ready(function() {
$('#faqs h3').each(function() {
var tis = $(this),
state = false,
answer = tis.next('div')
.hide()
.css('height','auto')
.slideUp();
tis.click(function() {
state = !state;
answer.slideToggle(state);
tis.toggleClass('active',state);
});
});
});
HTML
<div id="faqs">
<h3>Question 1:</h3>
<div>
<p>Answer to Question 1.</p>
</div>
<h3>Question 2:</h3>
<div>
<p>Answer to Question 2.</p>
</div>
</div>