Skip to content

Function: setClass()

ts
function setClass(el, className): void;

Sets the class attribute or className property of an element to the specified value.

Parameters

ParameterTypeDescription
elHTMLElement | SVGElementThe element to set the class attribute/property for.
classNamestringThe class name(s) to set on the element.

Returns

void

Example

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

Since

1.0.0

Released under the MIT License.