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 430 of 534
How to preview an image before it is uploaded in JavaScript?
In JavaScript, you can preview an image before uploading using the FileReader API. This allows users to see their selected image immediately without needing to upload it to a server first. How FileReader Works The FileReader API reads file contents asynchronously. For image preview, we use readAsDataURL() which converts the image file into a base64 data URL that can be displayed in an element. Example Image Preview Example ...
Read MoreHide div that contains specific text with JavaScript?
In JavaScript, you can hide div elements containing specific text by using getElementsByClassName() to select elements, then iterating through them and checking their content. When a match is found, set the element's display style to 'none'. Basic Approach The process involves three main steps: Get all div elements with a specific class Loop through each element and check its text content Hide matching elements by setting display: none Example: Hide Divs with Specific Text Hide ...
Read MoreHow to create a constant array in JavaScript? Can we change its values? Explain.
To create a const array in JavaScript, we use the const keyword before the array name. While the array reference cannot be reassigned, individual elements can be modified. A const array prevents reassignment of the entire array but allows mutation of its contents. This is because const creates an immutable binding, not an immutable value. Syntax const arrayName = [element1, element2, element3]; Example: Creating and Modifying a Const Array Const Array Example ...
Read MoreGet number from user input and display in console with JavaScript
Getting user input numbers in JavaScript involves capturing values from HTML input elements and converting them to numeric types for processing. This tutorial shows how to get a number from user input and display it in the console. HTML Structure First, create the HTML form with an input field and button: Get Number Input Number Input Example ...
Read MoreAdd oninput attribute to HTML element with JavaScript?
You can add the oninput attribute to HTML elements using JavaScript in two ways: using addEventListener() or directly setting the oninput property. Both methods allow you to dynamically attach input event handlers to elements. Using addEventListener() (Recommended) The addEventListener() method is the modern approach for attaching event listeners: Add oninput with addEventListener Enter the value: ...
Read MoreHow to stop a function during its execution in JavaScript?
In JavaScript, you can stop a function during execution using different techniques depending on the function type. For repeating functions like setInterval(), use clearInterval(). For one-time delayed functions, use clearTimeout(). Stopping setInterval() Functions The most common scenario is stopping a repeating function created with setInterval(): Stop Function Execution Start Function Stop Function ...
Read MoreRange Overflow and Range Underflow properties in JavaScript.
In JavaScript, the rangeOverflow and rangeUnderflow properties are part of the ValidityState object, used to check if form input values exceed their specified ranges. Range Underflow The rangeUnderflow property returns true if the element's value is less than the value specified in the min attribute. Range Overflow The rangeOverflow property returns true if the element's value is greater than the value specified in the max attribute. Syntax element.validity.rangeOverflow // true if value > max element.validity.rangeUnderflow // true if value < min Example ...
Read MoreAdd class (odd and even) in HTML via JavaScript?
JavaScript provides several ways to add CSS classes to HTML elements based on odd and even positions. You can use CSS nth-child selectors or JavaScript to dynamically add classes to elements. Method 1: Using CSS nth-child Selectors The simplest approach is using CSS nth-child(odd) and nth-child(even) selectors to style elements directly: Odd Even Classes .subjectName:nth-child(odd) { ...
Read MoreHow to add, access, delete, JavaScript object properties?
JavaScript objects are collections of key-value pairs where you can dynamically add, access, and delete properties. This guide demonstrates the fundamental operations for managing object properties. Syntax // Adding properties obj.propertyName = value; obj['propertyName'] = value; // Accessing properties obj.propertyName; obj['propertyName']; // Deleting properties delete obj.propertyName; delete obj['propertyName']; Example: Adding Properties Object Properties Add, Access, Delete JavaScript Object Properties Manage Properties function manageProperties() { let obj = { firstName: ...
Read MoreHow to add a property, method to a JavaScript constructor?
In JavaScript, you can add properties and methods to constructor functions using the prototype property. This allows all instances of the constructor to share these additions. Syntax // Add a property ConstructorName.prototype.propertyName = value; // Add a method ConstructorName.prototype.methodName = function() { // method body }; Example: Adding Property and Method to Constructor Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } ...
Read More