493 B
493 B
title, type, language, tags, author, cover, dateModified
| title | type | language | tags | author | cover | dateModified | |
|---|---|---|---|---|---|---|---|
| Add class to HTML element | snippet | javascript |
|
chalarangelo | shiny-mountains | 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