jQuery show/hide for FAQ using the next() function
- by jon_brockman
Maybe it's because it's Friday but I'm stuck on a simple problem. I'm building a FAQ page where a user clicks on a question, revealing the answer beneath it. I'm trying to get the next() function to just grab the next instance of an "answer" div but, despite not getting any JS errors, the hidden div isn't showing.
Here's the code:
.answer { display:none; }
$("a.question").click(function(){
$(this).next(".answer").toggle();
});
<a href="#" class="question">Queston 1</a>
<div class="answer">Answer 1</div>
<a href="#" class="question">Queston 2</a>
<div class="answer">Answer 2</div>