Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all css classes of all items of a <div> with jQuery?

Tags:

jquery

css

I have a div of nested ul/li items. each ul/li has a css class. Is there a clean way to remove all css class for all items inside this <div>?

edit: pls see here for code: http://jsfiddle.net/xjAkF/

like image 459
Laguna Avatar asked Jan 19 '12 20:01

Laguna


People also ask

How do I delete all classes in CSS?

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.

How do I remove a specific CSS class in jQuery?

jQuery removeClass() Method 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.

How do I remove all classes from an element?

To remove all classes from an element, use the removeAttribute() method, e.g. box. removeAttribute('class') . The method removes will remove the class attribute from the element, effectively removing all of the element's classes.


3 Answers

$('#myDiv ul, #myDiv li').removeClass();
like image 187
AlienWebguy Avatar answered Oct 17 '22 23:10

AlienWebguy


Just use .removeClass() if this is passed with no parameters it will remove all classes.

You were missing the # in the selector.

See revised code, here

@AlienWebguy, Has a better solution that way it only removes from the ul & li within the given id.

like image 44
kwelch Avatar answered Oct 18 '22 01:10

kwelch


To strip out classes from ALL children of an element, use find("*")

$('#divHtml').find("*").removeClass();
like image 32
Dave Avatar answered Oct 17 '22 23:10

Dave