Function removes css class names from element class
attribute.
Supports regexp as a class name (thing I wait from jQuery for years).
Preserves order, leaves no duplicate or trailing spaces in className
.
Regexp should be matched fully, not partially.
/foo-.*/
will match 'foo-bar'
in 'foo-bar baz'
/foo-/
will not.
^
and $
means start and end of class name chunk, not of the whole className
string
i
(case-independent) modifier search is supported
m
(multiline) modifier has no meaning
g
(global) modifier is ignored: all search behaves as global
removeClass(o, c)
o
required object whose className is changed
c
required class name: regexp or string (or anything that coerces to string, excepting null
and undefined
)
Returns: nothing
Why arrays? You can stay on string level (and still save a few bytes):
function(o,c){o.className=o.className.replace(/(\S+)\s*/g,function(f,x){return((c.exec?(c.exec(x)||0)[0]:c)==x)?'':f})}