Practical solutions

JavaScript Howtos How-To Guides

Solve the problem. Keep building. Collection of JavaScript how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Get the Current URL With JavaScriptIn this tutorial, we'll tackle about how to get the URL in JavaScript using four different methods. These methods will use window.location.href, document.location.href, document.URL, and document.baseURI. How to Define Do Nothing to Keep User on the Same Page in JavaScriptThis tutorial will discuss how to define do nothing to keep a user on the same page in JavaScript. The code keeps the user on the page when they click on the Cancel button of a confirm dialog window. How to Create a List of Objects in JavaScriptThis article discusses and demonstrates how to create a list of objects in JavaScript and their properties and methods. How to Clear Input in JavaScriptAn input field can be reset or associated with an empty value. The onfocus attribute can trigger a function to play the role of clearing an input. Also, fetching the input entry with value property and the reset method to clear inputs is pretty easy to grasp. How to Pause an Interval in JavaScriptJavaScript does not come with any built-in property or method to perform the play-pause task up to a certain time frame. In this case, we use the window.setInterval() method and a function that will play and pause on certain conditional statements. Another way is to follow up similar path using jQuery. How to Get onClick Button ID in JavaScriptThis tutorial will teach you how to get the ID of a clicked HTML button. We'll explain four methods that you can use to get the ID. These methods include the use of this.id, event.target.id, addEventListener, and jQuery. How to Disable Links in JavaScriptIn general, the href of an anchor tag can have a # to state that it is undefined. Also, we can use other ways to set the href undefined, but a predefined targeted link can be manually disabled by an eventListener, using name attribute and also by jQuery. How to Get Image Dimensions in JavaScriptThis tutorial shows how to get image dimensions using JavaScript. How to Get First and Last Day of Month Using JavaScriptThis tutorial shows how to get the last and first day of the month using methods in JavaScript. How to Disable Right Click on a Webpage in JavaScriptThis tutorial shows how we can disable right-click on a webpage. How to Calculate Age Given the Birth Date in YYYY-MM-DD Format in JavaScriptThis tutorial shows how you can calculate the age given the date of birth in the format of YYYY-MM-DD in JavaScript. How to Remove Commas From String in JavaScriptIn this tutorial, we will teach you how to remove commas from a string. We'll use the replace method, join method and lodash replace() method. To perform arithmetic computations, we'll use the parseFloat function on the resulting string. How to POST a JSON Object Using Fetch API in JavaScriptIn this tutorial, we will discuss how to send JSON data as a POST request to the server using the fetch method in JavaScript. How to Implement Singleton in JavaScriptIn today's post, we'll learn how to implement singleton classes in JavaScript. How to Implement Collision Detection in JavaScriptIn this article, we will see how to implement collision detection in JavaScript. How to Flatten Object in JavaScriptA flattened object contains all the nested objects' elements in a simplified form. Usually, the object's overall structure can be more complex and hard to parse. It is easier to flatten them to get a clear picture of a container. We will see the reduce(), flat() method and also a user-defined function to flatten objects. How to Check String is Palindrome in JavaScriptIn today's post, we'll learn how to check string/number is palindrome in JavaScript. The Elvis Operator in JavaScriptIn this article, we will see what is Nullish coalescing operator (elvis operator) and how to implement it inside JavaScript. How to Create Dropdown Using Onchange in JavaScriptThis tutorial will explain what are functions in JavaScript and what is the onchange function and how you can use JavaScript to create a dropdown menu using the onchange function. How to Validate a Credit Card Number in JavaScriptThis tutorial helps you to validate the credit card number in JavaScript. How to use strict in JavaScriptIn this article, learn the use strict feature in JavaScript. We will see how to create and execute the use strict keyword in our JavaScript code statements with different examples. How to Dump Object in JavaScriptThis tutorial shows how to dump an object in JavaScript. How to Create Unique ID With JavaScriptIn today's post, we'll learn how to create unique id with JavaScript. How to Build Coin Flip Simulator in JavaScriptThis tutorial will helps you to simulate coin flip using JavaScript, HTML, and CSS.