简体   繁体   English

单击触发器时打开和关闭同级div

[英]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. 我试图允许用户单击[+]触发器,并使其同级div打开和关闭以显示该主题的信息。

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() : 因为首先您应该解决this锚元素,其次要摆脱无用的.find()

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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