Added show/hide snippets

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

13
snippets/hide.md Normal file
View File

@ -0,0 +1,13 @@
### hide
Hides all the elements specified.
Use the spread operator (`...`) and `Array.forEach()` to apply `display: none` to each element specified.
```js
const hide = (...el) => [...el].forEach(e => e.style.display = 'none');
```
```js
hide(document.querySelector('img')); // Hides all <img> elements on the page
```

13
snippets/show.md Normal file
View File

@ -0,0 +1,13 @@
### show
Shows all the elements specified.
Use the spread operator (`...`) and `Array.forEach()` to clear the `display` property for each element specified.
```js
const show = (...el) => [...el].forEach(e => e.style.display = '');
```
```js
show(document.querySelector('img')); // Shows all <img> elements on the page
```