Hiya,
I have the following markup
<div class="question">
<h2>Title 1</h2>
<div class="answer">content 1</div>
</div>
<div class="question">
<h2>Title 2</h2>
<div class="answer">content 2</div>
</div>
<div class="question">
<h2>Title 3</h2>
<div class="answer">content 3</div>
</div>
I want to toggle the class "active" when a question div is clicked. I've attempted this following code:
<script type="text/javascript" >
$(document).ready(function(){
$(".question").click(function () {
$(this).toggleClass("active");
$(this).find("h2").toggleClass("active");
$(this).find("answer").toggleClass("active");
});
});
</script>
But this unfortunately adds the class active to every question,h2 and answer, rather than just the one that was clicked. I can't seem to get the syntax correct.
Can anyone point me in the right direction?
Cheers, Shadi