.hasClass(name)
Available on: InDom Tests whether the underlying element has the given CSS class.Parameters:
name {string} - Class name to test.
Returns: {boolean} - true if the class is present, false otherwise.Throws: Error - If the underlying element has been removed
Examples:// add 'clicked' class to any .example>div that gets clicked
const divs = $a('.example>div');
divs.onClick(n => n.addClass('clicked'));
// button: counts how many are currently clicked, then resets them
const sumResetClicked = $n('Sum and reset clicked');
$1('body').append(sumResetClicked);
sumResetClicked.onClick(() => {
let clicked = 0;
divs.each(n => {
if (n.hasClass('clicked')) { // test state
clicked++;
n.removeClass('clicked'); // reset state
}
});
console.log('clicked:' + clicked);
});Next: removeClass »