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/
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.
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.
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.
$('#myDiv ul, #myDiv li').removeClass();
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.
To strip out classes from ALL children of an element, use find("*")
$('#divHtml').find("*").removeClass();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With