Web Development Articles

Page 204 of 801

How can I show a hidden div when a select option is selected in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 17K+ Views

Showing and hiding elements dynamically is a fundamental technique in JavaScript web development. One common scenario is revealing a hidden div when a specific select option is chosen, creating interactive forms and user interfaces. Methods for Showing/Hiding Elements There are two main CSS properties for controlling element visibility: display: Removes element from document flow when hidden visibility: Keeps element's space but makes it invisible Method 1: Using visibility Property The visibility property hides the element while preserving its layout space: ...

Read More

Replace whitespace in different elements with the same class in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 504 Views

In this article we are going to learn about replacing whitespace in different elements with the same class in JavaScript. We'll explore multiple methods to remove spaces from text content across multiple HTML elements that share a common CSS class. Using split() and join() Methods The split() method divides a string into substrings and returns them as an array. When a separator is specified, the string is split at each occurrence of that separator. The join() method combines array elements back into a single string using a specified separator. Syntax string.split(" ").join("") Example ...

Read More

Use jQuery to get values of selected checkboxes?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 513 Views

jQuery provides an efficient way to get values of selected checkboxes using the :checked selector combined with checkbox input elements. This is useful for forms where users can select multiple options. Syntax $('input[type="checkbox"]:checked') // or $('input[name="checkboxName"]:checked') Basic Example Here's a complete example that demonstrates getting values of selected checkboxes: jQuery Checkbox Values Select your hobbies: ...

Read More

JavaScript subtraction of two float values?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 3K+ Views

JavaScript floating-point arithmetic can produce unexpected results due to precision limitations. To correctly subtract two float values and get accurate results, use parseFloat() to ensure proper number conversion and toFixed() to control decimal precision. The Problem with Float Subtraction Direct subtraction of floats can yield imprecise results: var result1 = 0.3 - 0.1; var result2 = 0.2 - 0.1; document.write("0.3 - 0.1 = " + result1 + ""); ...

Read More

Reducing array elements to all odds in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 198 Views

We need to write a JavaScript function that transforms an array by converting all numbers to odd values. The transformation rules are: If the number is odd, leave it unchanged. If the number is even, subtract 1 from it to make it odd. This ensures all elements in the resulting array are odd numbers. Example Here's how to implement this transformation: const arr = [5, 23, 6, 3, 66, 12, 8]; const reduceToOdd = (arr = []) => { const res = []; ...

Read More

How to stop the loop for JavaScript scroll down?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 868 Views

JavaScript scroll down loops can be extremely annoying and disruptive to a web page. Fortunately, it is relatively easy to stop the loop if you know what steps to take. In this article, we will discuss how to stop the JavaScript scroll down loop so that your website visitors don't have to keep scrolling endlessly. We'll also provide some tips on preventing these types of issues in the future. JavaScript method scrollBy() scrolls the web page to the specific number of pixels. When used in loops or intervals, it can create continuous scrolling effects that need proper control mechanisms. ...

Read More

How to make a setInterval() stop after some time or after a number of actions in JavaScript?

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

The setInterval() function repeatedly executes code at specified intervals. To stop it after some time or a number of actions, use clearInterval() with conditions. Method 1: Stop After Time Duration This example stops the interval after 10 seconds: Stop setInterval After Time var startTime = new Date().getTime(); ...

Read More

Array.prototype.fill() with object passes reference and not new instance in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 238 Views

When using Array.prototype.fill() with objects, JavaScript passes the same reference to all array positions instead of creating new instances. This means modifying one object affects all elements. The Problem with fill() and Objects Using fill() with an object creates multiple references to the same object: // This creates the same object reference in all positions let arr = new Array(3).fill({name: "John", age: 25}); console.log("Original array:"); console.log(arr); // Modifying one element affects all arr[0].name = "Alice"; console.log("After modifying arr[0].name:"); console.log(arr); Original array: [ { name: 'John', age: 25 }, { name: ...

Read More

All right triangles with specified perimeter in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

We are required to write a JavaScript function that takes in a number that specifies the perimeter for a triangle. Our function should return an array of all the right triangle side triplets whose perimeter matches the specified input. Understanding Right Triangles A right triangle satisfies the Pythagorean theorem: a² + b² = c², where c is the hypotenuse (longest side). For a given perimeter P, we need a + b + c = P. Algorithm Approach We use three nested loops to check all possible combinations of triangle sides. For each triplet, we verify: ...

Read More

Shortest syntax to assign properties from function call to an existing object in JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 178 Views

In JavaScript, you can quickly assign properties from a function call to an existing object using several concise syntaxes. This article explores the most efficient approaches to merge function-returned properties into existing objects. An object in JavaScript is a separate entity having properties and a type. JavaScript objects can have properties that specify their attributes. Using Spread Syntax (...) The spread syntax provides the shortest way to assign properties from a function call to an existing object. It expands an object's properties into a new object, effectively merging them. Syntax existingObject = { ...existingObject, ...

Read More
Showing 2031–2040 of 8,010 articles
« Prev 1 202 203 204 205 206 801 Next »
Advertisements