Hidding UL after H2
Hidding UL after H2
I have a series of <h2>'s followed by <ul>'s, and I want to have clicking a link in the <h2>'s hide the following <ul>. Here's my approximate html:
- <h2><a href="#">Level 2 header</a></h2>
- <ul>
- <li>List item</li>
- <li>List item 2</li>
- <li>List item 3</li>
- </ul>
- <h2><a href="#">Another level 2 header</a></h2>
- <ul>
- <li>List item</li>
- <li>List item 2</li>
- <li>List item 3</li>
- </ul>
And he's what I have in my custom.js:
- jQuery('.main h2 a').click(function() {
- if (jQuery(this).next('ul').is(':hidden')) {
- jQuery(this).next('ul').slideDown('fast');
- } else {
- jQuery(this).next('ul').slideUp('fast');
- }
- });
This doesn't work, but doesn't work, but if I do:
- jQuery('.main h2').click(function() { //only difference is that it's not targeting the "<a>", just the <h2>
- …
it does work. I want to have the <a> because otherwise it's not clear that it's clickable to users. What am I doing wrong?