472 B
472 B
title, type, tags, author, cover, dateModified
| title | type | tags | author | cover | dateModified | |
|---|---|---|---|---|---|---|
| Add class to HTML element | snippet |
|
chalarangelo | budapest-palace | 2020-12-30T19:21:15+02:00 |
Adds a class to an HTML element.
- Use
Element.classListandDOMTokenList.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