mirror of
https://github.com/Fechin/reference.git
synced 2026-11-22 05:51:48 +03:00
Release the latest generator
This commit is contained in:
1 parent
b520119d38
commit
15c93e54ee
484 files changed
+4969
-856
No files matched your search
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to check if an element is a descendant of another in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to check if an element is a descendant of another only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const isDescendant = (child, parent) => parent.contains(child);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to check if an element is focused in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to check if an element is focused only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const hasFocus = ele => (ele === document.activeElement);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to check if the touch events are supported in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to check if the touch events are supported only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const touchSupported = () => ('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to check if user scrolls to the bottom of the page in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to check if user scrolls to the bottom of the page only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const isAtBottom = () => document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight;
|
||||
```
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: How to detect internet explorer browser in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to detect internet explorer browser only using single line of code in JavaScript.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const isIE = !!document.documentMode;
|
||||
```
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: How to detect macos browser in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to detect macos browser only using single line of code in JavaScript.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const isMacBrowser = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to get all siblings of an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to get all siblings of an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const siblings = ele => [].slice.call(ele.parentNode.children).filter((child) => (child !== ele));
|
||||
```
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to get the position of an element relative to the document in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to get the position of an element relative to the document only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const getPosition = ele => (r = ele.getBoundingClientRect(), { left: r.left + window.scrollX, top: r.top + window.scrollY });
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```js {.wrap}
|
||||
getPosition(document.body); // { left: 0, top: 0 }
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to get the selected text in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to get the selected text only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const getSelectedText = () => window.getSelection().toString();
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to go back to the previous page in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to go back to the previous page only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
history.back();
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
history.go(-1);
|
||||
```
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: How to hide an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to hide an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
// Pick the method that is suitable for your use case
|
||||
const hide = ele => ele.style.display = 'none';
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const hide = ele => ele.style.visibility = 'hidden';
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const hide = ele => ele.hidden = true;
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to insert an element after other one in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to insert an element after other one only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const insertAfter = (ele, anotherEle) => anotherEle.parentNode.insertBefore(ele, anotherEle.nextSibling);
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const insertAfter = (ele, anotherEle) => anotherEle.insertAdjacentElement('afterend', ele);
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to insert an element before other one in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to insert an element before other one only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const insertBefore = (ele, anotherEle) => anotherEle.parentNode.insertBefore(ele, anotherEle);
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const insertBefore = (ele, anotherEle) => anotherEle.insertAdjacentElement('beforebegin', ele);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to insert given html after an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to insert given html after an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const insertHtmlAfter = (html, ele) => ele.insertAdjacentHTML('afterend', html);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to insert given html before an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to insert given html before an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const insertHtmlBefore = (html, ele) => ele.insertAdjacentHTML('beforebegin', html);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to redirect to another page in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to redirect to another page only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const goTo = url => location.href = url;
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to reload the current page in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to reload the current page only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const reload = () => location.reload();
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const reload = () => (location.href = location.href);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to replace an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to replace an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const replace = (ele, newEle) => ele.parentNode.replaceChild(newEle, ele);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to scroll to top of the page in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to scroll to top of the page only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const goToTop = () => window.scrollTo(0, 0);
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to serialize form data in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to serialize form data only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const serialize = formEle => Array.from(new FormData(formEle)).reduce((p, [k, v]) => Object.assign({}, p, { [k]: p[k] ? (Array.isArray(p[k]) ? p[k] : [p[k]]).concat(v) : v}), {});
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to show an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to show an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const show = ele => ele.style.display = '';
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
title: How to strip html from a given text in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to strip html from a given text only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const stripHtml = html => (new DOMParser().parseFromString(html, 'text/html')).body.textContent || '';
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: How to toggle an element in JavaScript
|
||||
tags:
|
||||
- JavaScript
|
||||
- ES6
|
||||
- one-line
|
||||
- js
|
||||
- DOM
|
||||
layout: note
|
||||
---
|
||||
|
||||
|
||||
|
||||
In this Article we will go through how to toggle an element only using single line of code in JavaScript.
|
||||
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => `Arrow Function`.
|
||||
<br/>
|
||||
<br/>
|
||||
Let's define this short function:
|
||||
|
||||
```js {.wrap}
|
||||
const toggle = ele => (ele.style.display = (ele.style.display === 'none') ? 'block' : 'none');
|
||||
```
|
||||
|
||||
### Or
|
||||
|
||||
```js {.wrap}
|
||||
const toggle = ele => ele.hidden = !ele.hidden;
|
||||
```
|
||||
Reference in new issue
Block a user