Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Web Development Articles
Page 511 of 801
How to add background music to your web page?
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 MoreHow to compare two objects in JavaScript?
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 MoreEnter key press event in JavaScript?
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 MoreHow to add 2 hours to a JavaScript Date object?
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 MoreHow to find the value of a button with JavaScript?
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 MoreHow to remove event handlers in JavaScript?
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 MoreHow to count JavaScript array objects?
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 MoreHow to format a number with two decimals in JavaScript?
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 MoreHow to copy text to the clipboard with JavaScript?
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 MoreJavaScript clearTimeout() & clearInterval() Method
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