Page MenuHomec4science

addClass.js
No OneTemporary

File Metadata

Created
Thu, Dec 12, 11:36

addClass.js

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);
}

Event Timeline