Skip to content

Function: hasClass() ​

ts
function hasClass(el, className): boolean;

Checks if an element has a specified CSS class, including SVG elements.

Parameters ​

ParameterTypeDescription
elHTMLElement | SVGElementThe element to check
classNamestringThe CSS class to check for

Returns ​

boolean

If the element has the specified CSS class, returns true; otherwise, returns false.

Example ​

ts
const el = document.createElement('div')
el.className = 'example-class'
console.log(hasClass(el, 'example-class'))

Since ​

1.0.0

Released under the MIT License.