Elementals.js

Latest Version: 3.0 RC 1 17 July 2017

Method _.Class.add

Summary:

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

Calling Convention:
_.Class.add(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');
_.Class.add(test, 'one');

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

Example #2 - Array of class names

JavaScript

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

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

Advertisement