If someone clicks on a link within a div with the class “foo” I want the list items within this div to show. How can I do this?
Here’s my failed attempt:
$('div > li').hide();
$('div.foo > a').click(function(event) {
$('div.foo > li').show();
event.preventDefault();
});
<ul>
<div class="foo">
<a href="#">Animals +</a>
<li>Cat</li>
<li>Dog</li>
<li>Rabbit</li>
</div>
</ul>
you have a problem with your html.
It should be something like this,
then in jQuery, like this,
here’s a fiddle, and try not to forget putting it inside the ready handler
Welcome to stackoverflow.com
Don’t forget to accept an answer