Elementals.js

Latest Version: 2.0 RC 3 14 March 2017

Method _.classSwap

Summary:

Swaps a class or list of classes from an element for another class or list of classes.

Calling Convention:
_.classSwap(Element, [String || Array], [String || Array])
Parameters:
Element
The element to remove classes from
String
A string containing a single class
Array
An array of class strings
Returns:
_.classRemove || _.classAdd

Example #1 -- String

HTML:

<p id="test" class="one"></p>

JavaScript:

var p = document.getElementById('test');
_.classSwap(p, 'one', 'two');
// p#test no longer has the class 'one' on it, but now has class 'two'.

Example #2 -- Array

HTML:

<p id="test" class="one two three"></p>

JavaScript:

var p = document.getElementById('test');
alert(_.classRemove(p, ['one', 'three', 'four'], ['five', 'six']);
// p#test is now class="two five six"
// alert would report true since actions were performed.