Rename js snippets
This commit is contained in:
20
snippets/js/s/hide-html-elements.md
Normal file
20
snippets/js/s/hide-html-elements.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: Hide elements
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [browser,css]
|
||||
cover: picking-berries
|
||||
dateModified: 2020-09-15T16:28:04+03:00
|
||||
---
|
||||
|
||||
Hides all the elements specified.
|
||||
|
||||
- Use the spread operator (`...`) and `Array.prototype.forEach()` to apply `display: none` to each element specified.
|
||||
|
||||
```js
|
||||
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||
```
|
||||
|
||||
```js
|
||||
hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
|
||||
```
|
||||
Reference in New Issue
Block a user