Element.hasClass method
Element › hasClass
Official
Checks if the element has a class.Signature:
hasClass(cls: string): booleanParameters:
| Parameter | Type | Description |
|---|---|---|
| cls | string | The class to check for. |
Returns: boolean — true if the element has the class, false otherwise.
Example:
const element = createEl('p');element.addClass('foo', 'bar');console.log(element.hasClass('foo')); // trueconsole.log(element.hasClass('baz')); // false