Skip to content

Element.hasClass method

Element › hasClass

Official

Checks if the element has a class.

Signature:

hasClass(cls: string): boolean

Parameters:

Parameter Type Description
cls string The class to check for.

Returns: booleantrue if the element has the class, false otherwise.

Example:

const element = createEl('p');
element.addClass('foo', 'bar');
console.log(element.hasClass('foo')); // true
console.log(element.hasClass('baz')); // false