Sign in

.addClass()

Add a classname to the selected elements' class attribute, while preserving any other classnames they may have.

Syntax

neon.addClass(string classname)

classname

The name of the classname to add.

Requirements

This method should be executed on a selection of elements. Please see the .select() method.

Return value

This method is chainable. It returns a copy of the Neon object on which it was called.

Description

This method allows you to add a classname to a number of elements, while preserving any other classnames they may have.

An element on a page may have a "class" attribute containing any number of classnames, separated by whitespace. You could set this attribute by calling .setAttribute(), but this overwrites the entire attribute, which would remove all existing classnames from your elements. .addClass() allows you to add an additional classname.

It's safe to call this on elements which already have the given classname. The classname won't be duplicated (though the order of classnames may be changed).