views:

36

answers:

3

I'd like to click a header link and have the block directly underneath hide or show (with slideToggle)

Thanks

<div class='header'><a href='#'>Header</a></div>

<div class='block'>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
</div>

<div class='header'><a href='#'>Header</a></div>

<div class='block'>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
</div>

<div class='header'><a href='#'>Header</a></div>

<div class='block'>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
<div class='test>Some Text</div>
</div>
A: 

Something like this should work:

$("DIV.header A").click(function(){$(this).parent().next().slideToggle();});
Bryan Downing
whats with the CAPS? Gzip (or deflate) compression works best on similarly cased text (mostly lower or mostly upper).
David Murdoch
No particular reason for the caps other than to denote a difference between a tag reference and a class reference. I didn't know that about gzip, thanks!
Bryan Downing
+3  A: 

Try this:

$(function(){
  $('.header a').click(function(){
    $(this).parent().next().slideToggle();
  });
});
Sarfraz
A: 
$(function()
{
    $(".header").click(function()
    {
        $(this).next().toggle();
    });
});

Or if you want a sliding toggle try:

$(function()
{
    $(".header").click(function()
    {
        $(this).next().slideToggle();
    });
});
Dan Diplo