GoScrobble/web/node_modules/dom-helpers/esm/addClass.js

11 lines
520 B
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
import hasClass from './hasClass';
/**
* Adds a CSS class to a given element.
*
* @param element the element
* @param className the CSS class name
*/
export default function addClass(element, className) {
if (element.classList) element.classList.add(className);else if (!hasClass(element, className)) if (typeof element.className === 'string') element.className = element.className + " " + className;else element.setAttribute('class', (element.className && element.className.baseVal || '') + " " + className);
}