user2252219
user2252219

Reputation: 865

Make toggle open only the actively clicked button, not all toggles

Right now I've got a toggle that when you click it opens every toggle that is named 'content'. How can I make it so that the toggles are opened individually?

Fiddle: http://jsfiddle.net/4N6xj/embedded/result/

$(document).ready(function(){
 var $content = $(".content").hide();
 $(".toggle").on("click", function(e){   
      $content.slideToggle(200);
  });
});

Upvotes: 0

Views: 114

Answers (1)

adeneo
adeneo

Reputation: 318172

Target the next() .content element from the clicked .toggle

$(document).ready(function(){
    $(".content").hide();

    $(".toggle").on("click", function(e){   
        $(this).next('.content').slideToggle(200);
    });
});

FIDDLE

Upvotes: 2

Related Questions