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
Javascript Articles
Page 436 of 534
How to disable mouse event on certain elements using JavaScript?
In JavaScript, you can disable mouse events on specific elements using the CSS pointer-events property. This technique prevents elements from receiving mouse clicks, hover effects, and other pointer interactions. Using pointer-events CSS Property The most effective method is setting pointer-events: none via JavaScript. This disables all mouse interactions on the target element. Disable Mouse Events body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; ...
Read MoreCan we have a return statement in a JavaScript switch statement?
Yes, you can use return statements in a JavaScript switch statement, but only when the switch is inside a function. The return statement will immediately exit the function with the specified value, making break statements unnecessary. How Return Statements Work in Switch When a return statement is executed in a switch case, it immediately exits the function and returns the value. This eliminates the need for break statements since the function execution stops. Example: Day Name Function Return ...
Read MoreNamed arguments in JavaScript.
Named arguments in JavaScript allow you to pass parameters to functions using an object, making function calls more readable and flexible. This technique uses object destructuring to extract named properties from the passed argument. Syntax function functionName({ param1, param2, param3 }) { // Function body } // Call with named arguments functionName({ param1: value1, param2: value2, param3: value3 }); Basic Example Named Arguments Example Named ...
Read MoreHow to load a JavaScript file Dynamically?
Loading JavaScript files dynamically allows you to add scripts to your webpage at runtime, which is useful for conditional loading, lazy loading, or modular applications. Basic Dynamic Loading Method The most common approach is creating a element and appending it to the document head: Dynamic JavaScript Loading body { font-family: "Segoe UI", Tahoma, ...
Read MoreHow can I remove a child node in HTML using JavaScript?
In JavaScript, you can remove child nodes from HTML elements using several methods. The most common approaches are removeChild() and the modern remove() method. Using removeChild() Method The removeChild() method removes a specified child node from its parent element. You need to call it on the parent element and pass the child node as a parameter. Remove Child Node body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result ...
Read MoreHow can we validate decimal numbers in JavaScript?
Validating decimal numbers in JavaScript is essential for form validation and data processing. There are several reliable methods to check if a value is a valid decimal number. Method 1: Using Regular Expression Regular expressions provide precise control over decimal number validation patterns: Decimal Validation Decimal Number Validation Validate ...
Read MoreHow to find keys of a hash in JavaScript?
In JavaScript, objects act as hash tables where you can store key-value pairs. To extract all keys from an object, use the built-in Object.keys() method, which returns an array of the object's property names. Syntax Object.keys(object) Parameters object: The object whose keys you want to retrieve. Return Value Returns an array of strings representing the object's own enumerable property names (keys). Example Find Hash Keys ...
Read MoreJavaScript program to decrement a date by 1 day
JavaScript provides several methods to manipulate dates. To decrement a date by 1 day, we can use the setDate() and getDate() methods together. Syntax date.setDate(date.getDate() - 1); Parameters date.getDate() - Returns the current day of the month (1-31) date.setDate() - Sets the day of the month for the date object Example: Basic Date Decrement Decrement Date by 1 Day body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...
Read MoreHow to implement asynchronous loop in JavaScript?
Asynchronous loops in JavaScript allow you to perform time-delayed or async operations within loops without blocking the main thread. This is essential when working with APIs, file operations, or timed delays. What is an Asynchronous Loop? A regular loop executes all iterations instantly. An asynchronous loop waits for each iteration to complete before moving to the next, using await with async functions. Using async/await with for Loop Asynchronous Loop ...
Read MoreNo. of ways to empty an array in JavaScript
JavaScript provides several methods to empty an array. Each method has different use cases and behaviors, especially when multiple references to the same array exist. Method 1: Setting to New Array This method creates a new empty array and assigns it to the variable. However, it doesn't affect other references to the original array. Setting to New Array let arr = [1, 2, 3, ...
Read More