Added hasClass/toggleClass snippets

This commit is contained in:
Angelos Chalaris
2017-12-28 23:46:33 +02:00
parent f91c846874
commit c8c40ae7c3
3 changed files with 28 additions and 0 deletions

13
snippets/toggleClass.md Normal file
View File

@ -0,0 +1,13 @@
### toggleClass
Toggle a class for an element.
Use `element.classList.toggle()` to toggle the specified class for the element.
```js
const toggleClass = (el, className) => el.classList.toggle(className);
```
```js
toggleClass(document.querySelector('p.special')[0],'special') // The paragraph will not have the 'special' class anymore
```