jQuery show/hide for FAQ using the next() function
Posted
by jon_brockman
on Stack Overflow
See other posts from Stack Overflow
or by jon_brockman
Published on 2010-05-14T14:20:23Z
Indexed on
2010/05/14
14:24 UTC
Read the original article
Hit count: 198
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>
© Stack Overflow or respective owner