gpt4 book ai didi

javascript - 如何使用Jquery的:not selector on a ul

转载 作者:行者123 更新时间:2023-11-28 15:42:22 25 4
gpt4 key购买 nike

我有一个与此类似的 ul 列表:

<ul>
<li class="category">Category 1
<ul>
<li class="product alpha_a">A Product</li>
<li class="product alpha_b">B product</li>
</ul>
</li>
<li class="category">Category 2
<ul>
<li class="product alpha_a">Another Product</li>
<li class="product alpha_c">c product</li>
</ul>
</li>
</ul>

我想要做的是隐藏不属于所选 alpha 类的 li 元素。我已经尝试过这个(此处简化):

$(".alpha_a").addClass("alphaselected");
$(".product li:not(.alphaselected)").hide();

但它不起作用。我也尝试过(以及其他许多尝试):

$("#sitemap li:not(.alphaselected,.category)").hide();

这似乎隐藏了一切。

有什么想法吗?

谢谢

最佳答案

试试这个:

$(".alpha_a").addClass("alphaselected");
$(".product:not(.alphaselected)").hide();

fiddle link

关于javascript - 如何使用Jquery的:not selector on a ul,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23383032/

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