jQuery 删除所有子元素的 CLASS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2034719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:38:18  来源:igfitidea点击:

Remove a CLASS for all child elements

jquerycss-selectors

提问by AnApprentice

Given the following HTML:

鉴于以下 HTML:

<div id="table-filters">
    <ul>
        <li class="active">blah</li>
        <li>blah</li>
        <li>blah</li>
        <li>blah</li>
    </ul>
</div>

Using table-filters as the jQuery selector, how can I clear out the elements having CLASS=ACTIVE, no matter which LIit happens to be on?

使用表过滤器作为 jQuery 选择器,我如何清除具有 的元素CLASS=ACTIVE,无论LI它碰巧在哪个上?

thanks

谢谢

回答by Joel

This should work:

这应该有效:

$("#table-filters>ul>li.active").removeClass("active");
//Find all `li`s with class `active`, children of `ul`s, children of `table-filters`

回答by insomiac

You can also do like this :

你也可以这样做:

  $("#table-filters li").parent().find('li').removeClass("active");