Web Development Articles

Page 511 of 801

How to add background music to your web page?

Vikyath Ram
Vikyath Ram
Updated on 15-Mar-2026 36K+ Views

To add background music on a web page, you can use the element or the legacy tag. The modern approach uses HTML5's element with the autoplay attribute to start music automatically when the page loads. For background music, set the audio player to be hidden by using CSS or by omitting controls. The loop attribute makes the audio repeat continuously. Always upload your music file to the server and reference it in the src attribute. Method 1: Using HTML5 Audio Element (Recommended) The element is the modern standard for embedding audio content: ...

Read More

How to compare two objects in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 24K+ Views

Objects in JavaScript are entities that consist of properties and types. For example, a car object might have properties like color, price, height, and width. const car = { color: 'Black', price: 2500000, height: '6 feet', width: '5 feet' } The equality operator (===) verifies whether two operands are equal and returns a Boolean value. However, it cannot directly compare objects because objects are reference types. document.write('tutorix' === 'tutorix' ...

Read More

Enter key press event in JavaScript?

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

The Enter key press event in JavaScript allows you to detect when users press the Enter key (keycode 13) and execute specific functions. This is commonly used for form submissions, search functionality, or triggering actions without clicking a button. Basic Syntax You can handle the Enter key using the onkeypress event handler: onkeypress="yourFunctionName(event)" The Enter key has a keycode of 13, which you can check using event.keyCode. Method 1: Using onkeypress Attribute Enter Key ...

Read More

How to add 2 hours to a JavaScript Date object?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 29K+ Views

In this tutorial, we will learn how to add 2 hours to a JavaScript Date object. Here we will discuss two methods which are following. Using the getTime() Method Using the setHours() Method Using the getTime() Method JavaScript date getTime() method returns the numeric value corresponding to the time for the specified date according to universal time. The value returned by the getTime() method is the number of milliseconds since 1 January 1970 at 00:00:00. Syntax Date.getTime() Approach To add 2 hours to the Date Object first, we get ...

Read More

How to find the value of a button with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 32K+ Views

In this tutorial, we will learn how to find the value of a button with JavaScript. Button elements often have a value attribute that stores important data for form processing or identification purposes. JavaScript provides the value property to access this attribute programmatically. Understanding how to retrieve button values is essential when working with HTML forms and interactive web applications. Button value Property The button value property returns the value of the value attribute assigned to a button element. This property is commonly used to distinguish between multiple buttons or pass specific data when forms are submitted. ...

Read More

How to remove event handlers in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 30K+ Views

An event is defined as a change in an object's state. There are a number of events in HTML that show when a user or browser performs a certain action. JavaScript responds to these events when JavaScript code is embedded in HTML and allows execution. The process of responding to events is known as event handling. As a result, JavaScript uses event handlers to handle HTML events. In this article, we are going to discuss how to remove event handlers in JavaScript. Here, we use the removeEventListener() method to remove an event handler from an element in JavaScript. ...

Read More

How to count JavaScript array objects?

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

In this tutorial, we will learn to count JavaScript array objects. The array is the data structure containing the strings, numbers, objects, etc., in JavaScript. The object is the one kind of entity that contains properties and methods related to it. We can access the object's properties and invoke the object method using the object's references. Generally, To find the array length, we can use the array.length property and it returns the total number of elements that the array includes. But what if we need to count only object elements? Here, this tutorial has various approaches to counting ...

Read More

How to format a number with two decimals in JavaScript?

Kumar Ishan
Kumar Ishan
Updated on 15-Mar-2026 102K+ Views

This tutorial will teach us how to format a number with two decimals using JavaScript. Formatting a number means rounding the number up to a specified decimal place. In JavaScript, we can apply many methods to perform the formatting. Some of them are listed as follows − The toFixed() Method Math.round() Method Math.floor() Method Math.ceil() Method Using toFixed() Method (Recommended) The toFixed() method formats a number with a specific number of digits to the right of the decimal. It returns a string representation ...

Read More

How to copy text to the clipboard with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 678 Views

To copy text to the clipboard in JavaScript, we can use both modern and legacy approaches. The modern navigator.clipboard API is recommended, while the older document.execCommand() method provides fallback support. Modern Approach: Using navigator.clipboard API The navigator.clipboard.writeText() method is the modern standard for copying text. It returns a Promise and works asynchronously. button { border: none; ...

Read More

JavaScript clearTimeout() & clearInterval() Method

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

In JavaScript, the clearTimeout() and clearInterval() methods are used to clear timers. When we set a timer using setTimeout() or setInterval() methods, the browser allocates memory to track it. Therefore, we use these methods to release that memory and avoid unnecessary function calls. It is best practice to clear timers when they are no longer needed to prevent memory leaks and unwanted executions. JavaScript clearTimeout() Method The clearTimeout() method clears a timeout that was previously set by setTimeout(). It prevents the scheduled function from executing if called before the timeout completes. Syntax clearTimeout(timeoutID) Parameters ...

Read More
Showing 5101–5110 of 8,010 articles
« Prev 1 509 510 511 512 513 801 Next »
Advertisements