Add addClass, removeClass snippets

This commit is contained in:
Chalarangelo
2020-12-30 19:21:15 +02:00
parent 1ee4c38c0f
commit 0e8246002f
2 changed files with 34 additions and 0 deletions

17
snippets/removeClass.md Normal file
View File

@ -0,0 +1,17 @@
---
title: removeClass
tags: browser,beginner
---
Removes a class from an HTML element.
- Use `Element.classList` and `DOMTokenList.remove()` to remove the specified class from the element.
```js
const removeClass = (el, className) => el.classList.remove(className);
```
```js
removeClass(document.querySelector('p.special'), 'special');
// The paragraph will not have the 'special' class anymore
```