OK, I have a list of <li>
s with some content in like so:
<div>
<ul>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
<li><h4>...</h4><div>...</div></li>
</ul>
</div>
Using jQuery, the <div>
is hidden. When one of the <h4>
s is 'clicked' the <div>
is made visible, and when clicked again is made invisible.
This all works fine except, when clicking on the <h4>
in any <li>
all of the <div>
s are made visible.
How do I stop this happening? I only want the <div>
in the same <li>
that the <h4>
that is clicked to be made visible.
This is my jQuery:
$(document).ready(function() {
$('div div').hide();
$('div h4').click(function(){
if($('div div').is(':hidden')) {
$('div div').show();
$('div li').addClass('open');
}
else {
$('div div').hide();
$('div li').removeClass('open');
}
});
});