Update hide.md

This commit is contained in:
Isabelle Viktoria Maciohsek
2021-07-23 16:08:32 +03:00
committed by GitHub
parent 3f2744e9e5
commit e35b4e0bb3

View File

@ -7,12 +7,12 @@ lastUpdated: 2020-09-15T16:28:04+03:00
Hides all the elements specified.
- Use `NodeList.prototype.forEach()` to apply `display: none` to each element specified.
- Use the spread operator (`...`) and `Array.prototype.forEach()` to apply `display: none` to each element specified.
```js
const hide = nodes => nodes.forEach(e => (e.style.display = 'none'));
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
```
```js
hide(document.querySelectorAll('img')); // Hides all <img> elements on the page
hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
```