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
.
Let's define this short function:
const siblings = ele => [].slice.call(ele.parentNode.children).filter((child) => (child !== ele));
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
.
Let's define this short function:
const getPosition = ele => (r = ele.getBoundingClientRect(), { left: r.left + window.scrollX, top: r.top + window.scrollY });
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
.
Let's define this short function:
const getSelectedText = () => window.getSelection().toString();
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
.
Let's define this short function:
history.back();
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
.
Let's define this short function:
// Pick the method that is suitable for your use case
const hide = ele => ele.style.display = 'none';
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
.
Let's define this short function:
const insertAfter = (ele, anotherEle) => anotherEle.parentNode.insertBefore(ele, anotherEle.nextSibling);
In this Article we will go through how to get the current quarter of a date 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
.
Let's define this short function:
const getQuarter = (d = new Date()) => Math.ceil((d.getMonth() + 1) / 3);
In this Article we will go through how to get the current timestamp in seconds 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
.
Let's define this short function:
const ts = () => Math.floor(new Date().getTime() / 1000);
In this Article we will go through how to get the day of the year from a date 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
.
Let's define this short function:
const dayOfYear = date => Math.floor((date - new Date(date.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24));
In this Article we will go through how to get the first date in the month of a date 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
.
Let's define this short function:
const getFirstDate = (d = new Date()) => new Date(d.getFullYear(), d.getMonth(), 1);