Elementals.js

Latest Version: 2.0 RC 3 14 March 2017

Method _.classExists

Summary:

Checks if a class or any values in an array of classes exists on an element.

Calling Convention:
_.classExists(Element, [String || Array])
Parameters:
Element
The element to check for presence of classes
String
A string to be searched for in Element.className
Array
An array of strings to be searched for.
Returns:
True if at least one class is present.
False if no classes are present

Example

HTML:

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

JavaScript:

var p = document.getElementById('test');
console.log('p# test contains "one" is ' + _.classExists(p, 'one'));
console.log('p# test contains "two" is ' + _.classExists(p, 'two'));
console.log('p# test contains "one" or "two" is ' + _.classExists(p, ['one', 'two']));