Aberidius Aberidius - 4 months ago 11
HTML Question

click opens all divs instead of one

I'm really new to jQuery, i'm in the middle of a small crisis.

$(document).ready(function(){
$(".help_box").click(function(){
$(".help_box_answer").toggle(400);
});
});


Here's the HTML itself

<div class="help_box">
<div class="help_box_title">title box</div>
<div class="help_box_answer">
<p>Hidden message</p>
</div>
</div>


the
class="help_box_answer"
is set to
display:none


When I click on the div, this happens

enter image description here

Answer

Use this to refer to only the element you're clicking on instead of all the divs with the same class:

$(document).ready(function(){
    $(".help_box").click(function(){
        $(this).find(".help_box_answer").toggle(400);
    });
});

jsFiddle example