Elementals.js

Latest Version: 2.0 RC 3 14 March 2017

Method _.classAdd

Summary:

Adds a single class or an array of classes to an element.

Calling Convention:
_.classAdd(Element, [String || Array])
Parameters:
Element
The element you want to add a class or multiple classes to.
String
A className string to be added.
Array
An array of className strings to be added.
Returns:
True if at least one class was added.
False if no classes were added

Example #1 - className string

JavaScript

var test = document.getElementById('test');
_.classAdd(test, 'one');

Element#test will now have the class "one" on it.

Example #2 - Array of class names

JavaScript

var test = document.getElementById('test');
_.classAdd(test, ['one', 'two', 'three']);

Element#test will now have the classes "one", "two", and "three" on it.