gpt4 book ai didi

jquery - 单击任何 li 时隐藏 ul

转载 作者:行者123 更新时间:2023-12-01 04:00:48 26 4
gpt4 key购买 nike

我有过滤器,按照下面的代码片段按月显示数据

当单击“nowShowing”类的任何 li 时,我想关闭/隐藏具有“children”类的 ul。请帮助识别事件,我在下面尝试过但仍然不起作用

  $('.children').click(function() {
children.hide();
})
<ul class="filters">
<li class="parent active"><a href="javascript:void(0);" class="customfilters">Filter by Month</a>
<ul class="children">
<li class="nowShowing"><a class="all" id="all2" href="#" data-filter="*">All</a></li>
<li class="nowShowing"><a href="#" data-filter=".June" class="June">June</a></li>
<li class="nowShowing"><a href="#" data-filter=".July" class="July">July</a></li>
<li class="nowShowing"><a href="#" data-filter=".August" class="August">August</a></li>
<li class="nowShowing"><a href="#" data-filter=".September" class="September">September</a></li>
</ul>
</li>
</ul>

最佳答案

使用.closest隐藏

 $('.nowShowing').click(function(){
$(this).closest('.children').hide();
});
$('.customfilters').click(function(){
$('.children').show();
});

演示:https://jsfiddle.net/gaq23jbL/6/

关于jquery - 单击任何 li 时隐藏 ul,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44536693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com