Web Development Articles

Page 510 of 801

How to detect a mobile device with JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 70K+ Views

In this tutorial, we are going to learn how can we detect a mobile device over which we are working using JavaScript. Approach 1: Using the navigator.userAgent Property To detect a mobile device with JavaScript we are going to use the window navigator object which contains all the information regarding a browser. The property which we will use to detect a mobile device will be the userAgent property which is used to return the user-agent header sent to the server by the browser. The value we receive from this property is the browser name, version, and platform i.e., ...

Read More

How to pad a number with leading zeros in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 71K+ Views

In this tutorial, we will learn how to pad a number with leading zeros in JavaScript. Padding a number can be done in different ways in JavaScript. In this tutorial, we will see the two most popular ways of doing it − Using the String padStart() method Using the Array object constructor and join() method Using the String padStart() Method In JavaScript, the String object's padStart() method is useful to pad a number with leading zeros. It takes two parameters, the first one is the total length of the targeted or ...

Read More

How to remove existing HTML elements in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 47K+ Views

This article discusses how to delete existing HTML elements in JavaScript. To remove HTML elements, you first need to select the element from the document, then use methods like remove() and removeChild() to delete them from the DOM. Using the remove() Method The remove() method directly removes an element from the DOM. It's the simplest approach for modern browsers. Syntax element.remove(); Example Remove Element Example This heading will be removed This paragraph will remain ...

Read More

How to check whether a checkbox is checked in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 54K+ Views

In this tutorial, we will learn to check whether a checkbox is checked in JavaScript. The checkbox is an input type in HTML that works as a selection box. Unlike radio buttons which allow users to select only one value from a group, checkboxes allow users to select multiple values. HTML can add checkboxes to webpages, but JavaScript is needed to add behavior based on whether checkboxes are checked or not. We'll learn to check both single and multiple checkboxes. Check if a Single Checkbox is Selected To check if a checkbox is selected, we access the ...

Read More

How to use an HTML button to call a JavaScript function?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 67K+ Views

We use the onclick event attribute property of the HTML button to call a JavaScript function. The JavaScript code provided in the onclick attribute executes when the button is clicked. There are various attributes provided with the button tag in HTML that allows us to customize the button's functionality and also let us decide how and what the button triggers. Using the onclick Event in JavaScript The onclick event of the button element expects JavaScript code that is triggered when the button is clicked upon. So we put the function that needs to be called in the onclick ...

Read More

How to reset or clear a form using JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 45K+ Views

This tutorial teaches us how to reset or clear a form using JavaScript. This option is very helpful for users when they have filled the wrong data and want to clear everything at once. The reset() method provides an efficient way to restore all form fields to their initial values. The reset() method is a built-in JavaScript function that clears all input fields in a form and restores them to their default values. Syntax document.getElementById("formId").reset(); // or document.forms["formName"].reset(); The getElementById() method retrieves the form element by its ID, and then reset() clears all form ...

Read More

How to import local json file data to my JavaScript variable?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 34K+ Views

When working with local JSON files in JavaScript, you need to import the data into your JavaScript variables. This article demonstrates how to load JSON data from a local file using different methods depending on your environment. Let's say we have an employees.json file in our project directory: Sample JSON File employees.json { "Employees": [ { "userId": "ravjy", "jobTitleName": "Developer", "firstName": "Ran", "lastName": "Vijay", ...

Read More

How to change the font color of a text using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 43K+ Views

This tutorial teaches us to change the font color of text using JavaScript. While working with JavaScript and developing the frontend of an application, you may need to change the font color of text when an event occurs. For example, if you have an application that can turn a device on or off with a button, you might want the button text to be green when the device is on and red when it's off. JavaScript provides several methods to accomplish this dynamic color changing. Using the style Property The most common approach is to access an ...

Read More

How to get first and last date of the current month with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 35K+ Views

In this tutorial, we will look at how to get the first and last date of the current month using JavaScript. Working with dates is common in web development, especially when building calendars, date pickers, or time-based features. JavaScript provides built-in methods to handle dates, and there are also external libraries that make date manipulation easier. Following are the approaches to get the first and last date of the month using JavaScript − Using a Date Object Using the Moment.js Library Using a Date Object JavaScript's built-in ...

Read More

How to pass an object as a parameter in JavaScript function?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 34K+ Views

In this tutorial, we will learn how to pass an object as a parameter in a JavaScript function. One of JavaScript's data types is represented by the Object type. It is used to store keyed collections as well as more complex entities. The Object() constructor or the object initializer / literal syntax can be used to create objects. Almost all JavaScript objects are instances of Object; a typical object inherits properties (including methods) from Object.prototype, though these properties may be shadowed (a.k.a. overridden). Following are the methods used to pass an object as a parameter in a ...

Read More
Showing 5091–5100 of 8,010 articles
« Prev 1 508 509 510 511 512 801 Next »
Advertisements