classNames
deprecated

classNames(element) -> Enumerable

Returns a new instance of ClassNames, an Enumerable object used to read and write CSS class names of element.

Element#classNames has been deprecated. Please use Element#addClassName, Element#removeClassName and Element#hasClassName instead.

If you need to access class names as an array, try $w(element.className).

Practically, this means that you have access to your element's CSS class names as an Enumerable rather than as the string that the native className property gives you (notice the singular form).

On top of that, this Enumerable object is extended with a series of methods specifically targeted at dealing with CSS class names: set(className), add(className) and remove(className). These are used internally by Element.addClassName, Element.toggleClassName and Element.removeClassName, but—unless you want to do some pretty wacky stuff—you usually won't need to use them.

Examples


<div id="mutsu" class="apple fruit food"></div>

$('mutsu').classNames().inspect()
// -> "#<Enumerable:['apple', 'fruit', 'food']>"

// change its class names:
$('mutsu').className = 'fruit round'

$('mutsu').classNames().inspect()
// -> "#<Enumerable:['fruit', 'food']>"