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
Object Oriented Programming Articles
Page 103 of 589
Hide 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 MorePositive integer square array JavaScript
In JavaScript, we often need to filter arrays to extract specific types of numbers and perform operations on them. This example demonstrates how to find positive integers in an array and return the sum of their squares. Problem Statement Given an array containing various numbers (positive, negative, decimals, and integers), we need to write a function that returns the sum of squares of all positive integers only. Solution We'll use the reduce() method to iterate through the array and accumulate the sum of squares for positive integers: const arr = [1, -4, 6.1, 0.1, ...
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 MoreMake numbers in array relative to 0 – 100 in JavaScript
Let's say, we have an array that contains some numbers, our job is to write a function that takes in the array and maps all the values relative to 0 to 100. This means that the greatest number should get replaced by 100, the smallest by 0, and all others should get converted to specific numbers between 0 and 100 according to the ratio. Understanding the Formula To normalize values to a 0-100 scale, we use the formula: normalizedValue = ((value - min) / (max - min)) * 100 This formula ensures the smallest ...
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 More