Element.classList
and DOMTokenList.add()
to add the specified class to the element.const addClass = (el, className) => el.classList.add(className);
addClass(document.querySelector('p'), 'special'); // The paragraph will now have the 'special' class
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️