通过Jquery单击隐藏一个又一个元素

时间:2013-06-18 00:27:49

标签: jquery html

我有一些同一类'showFaq'的元素。我想这样做,所以我一次只能在'showFaq'类中打开一个元素。

 $(".subFaq").hide();
 $(".showFaq").click(function(){
  $(this).next().slideToggle('slow');
});

谢谢!

2 个答案:

答案 0 :(得分:0)

试试这个

$(".subFaq").hide();
$(".showFaq").click(function(){
    $(".subFaq").hide(); // hide all the faq before showing the current one
    $(this).next().slideToggle('slow');
});

答案 1 :(得分:0)

您必须首先定义常见问题解答的父级,然后

$(".showFaq").click(function(){
     $('#parent').children().filter(':not(this)').hide();
}

尚未测试但希望它能够正常工作

相关问题