Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Add class to HTML element
type: snippet
language: javascript
tags: [browser]
author: chalarangelo
cover: budapest-palace
dateModified: 2020-12-30T19:21:15+02:00
---
Adds a class to an HTML element.
- Use `Element.classList` and `DOMTokenList.add()` to add the specified class to the element.
```js
const addClass = (el, className) => el.classList.add(className);
```
```js
addClass(document.querySelector('p'), 'special');
// The paragraph will now have the 'special' class
```