简体   繁体   中英

Open and close a sibling div when trigger is clicked

I'm trying to allow users to click on the [+] trigger and have it's sibling div open and close to display that topic's information.

Why can't this find the sibling?

$('.moreInfo').hide();
$('a.triggerButton').click(function(){
  var $this = $('a.triggerButton');
  $this.find().siblings('.moreInfo').slideToggle('fast');
});

I made a fiddle here . Thanks for your help.

Because firstly you should address this anchor element, and secondly get rid of useless .find() :

$("a.triggerButton").click(function() {
    $(this).siblings(".moreInfo").slideToggle("fast");
});

DEMO: http://jsfiddle.net/JFw9g/9/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM