Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a CLASS for all child elements

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

like image 832
AnApprentice Avatar asked Jan 09 '10 19:01

AnApprentice


People also ask

How do you remove a class in CSS?

The syntax for Removing CSS classes to an element:removeClass(class_name);

How do I remove all CSS from a class?

To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.

What is removeClass in JavaScript?

The removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.


2 Answers

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` 
like image 88
Joel Avatar answered Sep 30 '22 12:09

Joel


You can also do like this :

  $("#table-filters li").parent().find('li').removeClass("active"); 
like image 43
insomiac Avatar answered Sep 30 '22 14:09

insomiac