Is there any better way to do this?
$('element').removeClass('class-1').removeClass('class-2').removeClass('class-3').removeClass('class-5') ...
to .removeClass('class-105')
:)
I want to remove all class-(n) classes.
Is there any better way to do this?
$('element').removeClass('class-1').removeClass('class-2').removeClass('class-3').removeClass('class-5') ...
to .removeClass('class-105')
:)
I want to remove all class-(n) classes.
Here's a small jQuery plugin I'm using for this purpose:
You use it like this:
Doing it in a better way using css selector,
[type*=value]
Edit :
Demo : http://jsbin.com/opebu4/2
...or you can use a starts-with selector if you know the possible class names you'd like to remove. The nasty part of the task is the sheer number of classes to look for...
Get the classes of the element, process it as a string, and put it back:
Edit:
The
attr
method has since changed, and it no longer reads properties, so you have to use the attribute nameclass
instead of the property nameclassName
: