diff --git a/README.md b/README.md index 46f01c489..bfaf1e8bc 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,11 @@ * [`elementIsVisibleInViewport`](#elementisvisibleinviewport) * [`getScrollPosition`](#getscrollposition) * [`getURLParameters`](#geturlparameters) +* [`hide`](#hide) * [`httpsRedirect`](#httpsredirect) * [`redirect`](#redirect) * [`scrollToTop`](#scrolltotop) +* [`show`](#show) @@ -1762,6 +1764,29 @@ getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam [⬆ Back to top](#table-of-contents) +### 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')); +``` + +
+Examples + +```js +hide(document.querySelectorAll('img')); // Hides all elements on the page +``` + +
+ + +[⬆ Back to top](#table-of-contents) + + ### httpsRedirect Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history. @@ -1835,6 +1860,29 @@ scrollToTop(); +[⬆ Back to top](#table-of-contents) + + +### 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 = '')); +``` + +
+Examples + +```js +show(document.querySelectorAll('img')); // Shows all elements on the page +``` + +
+ + [⬆ Back to top](#table-of-contents) ## Date diff --git a/docs/index.html b/docs/index.html index f49e7dd18..8a310ba88 100644 --- a/docs/index.html +++ b/docs/index.html @@ -160,9 +160,11 @@ elementIsVisibleInViewport getScrollPosition getURLParameters +hide httpsRedirect redirect scrollToTop +show

Date

getDaysDiffBetweenDates @@ -859,6 +861,13 @@ Pass location.search as the argument to apply to the current
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
 
+

hide

+

Hides all the elements specified.

+

Use the spread operator (...) and Array.forEach() to apply display: none to each element specified.

+
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
+
+
hide(document.querySelectorAll('img')); // Hides all <img> elements on the page
+

httpsRedirect

Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.

Use location.protocol to get the protocol currently being used. If it's not HTTPS, use location.replace() to replace the existing page with the HTTPS version of the page. Use location.href to get the full address, split it with String.split() and remove the protocol part of the URL.

@@ -889,6 +898,13 @@ Scroll by a fraction of the distance from the top. Use window.requestAnima
scrollToTop();
 
+

show

+

Shows all the elements specified.

+

Use the spread operator (...) and Array.forEach() to clear the display property for each element specified.

+
const show = (...el) => [...el].forEach(e => (e.style.display = ''));
+
+
show(document.querySelectorAll('img')); // Shows all <img> elements on the page
+

Date

getDaysDiffBetweenDates

Returns the difference (in days) between two dates.

diff --git a/snippets/hide.md b/snippets/hide.md index b19486df4..82a02a4b0 100644 --- a/snippets/hide.md +++ b/snippets/hide.md @@ -5,7 +5,7 @@ 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'); +const hide = (...el) => [...el].forEach(e => (e.style.display = 'none')); ``` ```js diff --git a/snippets/show.md b/snippets/show.md index 2e2302d19..cf30be9b7 100644 --- a/snippets/show.md +++ b/snippets/show.md @@ -5,7 +5,7 @@ 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 = ''); +const show = (...el) => [...el].forEach(e => (e.style.display = '')); ``` ```js