How to construct a URL in JavaScript
A short guide on how to correctly construct a URL in JavaScript.
The JavaScript snippet collection contains a wide variety of ES6 helper functions. Browser snippets include helper functions for selecting, traversing, and manipulating DOM elements, while general-purpose helpers can be found in the JavaScript snippet collection.
A short guide on how to correctly construct a URL in JavaScript.
There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
Smooth-scrolls to the top of the page.
Learn how to work with HTML element classes in JavaScript, from simple class checks to adding, removing and toggling classes.
Increase your JavaScript code's performance when working with the DOM by leveraging this simple trick.
Learn how to get the currently selected text in the browser using JavaScript.
Ever wanted to create your own jquery-like query selector shorthand? Here's how!
If you want to create an element from a string without appending it to the document, you can use a few lines of JavaScript.
CORS (Cross-Origin Resource Sharing) trips up many developers, but it's pretty easy to wrap your head around.
Here's a quick and easy way to select the currently focused DOM element in JavaScript.
Learn how to quickly remove an element from the DOM using JavaScript.
Learn how to check if an element is visible in the browser's viewport, using this simple technique.
Learn a simple way to get the browser's current URL in JavaScript.
Calculate the coordinates of the current scroll position in the browser window using JavaScript.
Learn how to insert an HTML string before or after the start of a specified element using JavaScript.
If you've ever needed to check if the bottom of the page is visible, this snippet will help you do just that.
Check if localStorage
or sessionStorage
is enabled in the browser, using a simple JavaScript function.
Use a media query to check if the user prefers a light or dark color scheme.
Easily and reliably calculate the width of the browser's vertical scrollbar with JavaScript.
Can you tell if two URLs are on the same origin? Here's a very simple way to do so.