instance method Element#addClassName

View source on GitHub →

Element#addClassName(className) → Element
  • className (String) – The class name to add.

Adds the given CSS class to element.

Example

Assuming this HTML:

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

Then:

$('mutsu').className;
// -> 'apple fruit'
$('mutsu').addClassName('food');
$('mutsu').className;
// -> 'apple fruit food'

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.