Remove a CLASS for all child elements

JqueryCss Selectors

Jquery Problem Overview


Given the following 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 LI it happens to be on?

thanks

Jquery Solutions


Solution 1 - Jquery

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`

Solution 2 - Jquery

You can also do like this :

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnApprenticeView Question on Stackoverflow
Solution 1 - JqueryJoelView Answer on Stackoverflow
Solution 2 - JqueryinsomiacView Answer on Stackoverflow