Home > DeveloperSection > Forums > How to toggle next hidden div on click
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    January-28-2015 10:09 PM

 ASP.Net JQuery  JavaScript 
Ratings:


 1 Reply(s)
 504  View(s)
Rate this:

I have the following setup. I want to toggle the expanded div when clicking the expander link. I only want to expand the div directly next to the link though. How can I do this?

<a class="expander" href="#"><?php echo get_the_title($post->ID); ?></a>

<div class="expanded">

    content here

</div>

 

<a class="expander" href="#"><?php echo get_the_title($post->ID); ?></a>

<div class="expanded">

    content here

</div>

 

<a class="expander" href="#"><?php echo get_the_title($post->ID); ?></a>

<div class="expanded">

    content here

</div>

Here's my jquery:

$('.expander').click(function() {

    event.preventDefault();

    $(this).siblings('expanded').toggle();

});



Hugh Jackman
Hugh Jackman

Total Post:52

Points:366
Posted on    January-28-2015 10:40 PM

Use next instead. I think this should work:

$('.expander').click(function() {

    $(this).next('.expanded').first().toggle();

}); 


Don't want to miss updates? Please click the below button!

Follow MindStick