Articles on Trending Technologies

Technical articles with clear explanations and examples

How to stop dragend's default behavior in drag and drop?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 264 Views

To stop dragend's default behavior in drag and drop operations, you need to use preventDefault() and detect if the mouse is over a valid drop target. Here are several approaches to handle this properly. Using preventDefault() Method The most straightforward way is to call preventDefault() in the dragend event handler: Drag me Drop here const dragItem = document.getElementById('dragItem'); const dropZone = document.getElementById('dropZone'); dragItem.addEventListener('dragend', function(event) { event.preventDefault(); console.log('Dragend default behavior prevented'); }); dragItem.addEventListener('dragstart', function(event) { event.dataTransfer.setData('text/plain', event.target.id); }); dropZone.addEventListener('dragover', function(event) ...

Read More

HTML5 & JavaScript: resolution or size of

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 829 Views

HTML5 provides two approaches for capturing photos from mobile devices with different levels of control over image resolution and size. HTML Media Capture The simplest approach uses HTML's capture attribute with accept="image/*" on input elements to access the device camera. HTML Media Capture Capture Photo with HTML document.getElementById('camera').addEventListener('change', function(e) { ...

Read More

Removing a node in a Javascript Tree

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In JavaScript, removing a node from a tree is a fundamental operation that requires handling different scenarios based on the node's structure. This article covers the three main cases for node deletion in Binary Search Trees (BST). Tree Structure and Traversal Overview A tree is a nonlinear data structure consisting of nodes connected by edges. Tree traversal retrieves and processes data from each node in a specific order: In-order traversal − Follows the path (Left → Root → Right) Pre-order traversal − Follows the path (Root → Left → Right) Post-order traversal − Follows the path ...

Read More

How to select a radio button by default in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 14K+ Views

Radio buttons allow users to select one option from multiple choices. Unlike checkboxes, only one radio button in a group can be selected at a time. To make a radio button selected by default, you can use the HTML checked attribute or JavaScript's checked property. Basic Radio Button Syntax Radio buttons are created using the HTML tag with type="radio": Option 1 Option 2 Method 1: Using HTML checked Attribute The simplest way to select a radio button by default is adding the checked attribute directly in HTML: ...

Read More

How to hide a navigation menu on scroll down with CSS and JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 6K+ Views

To hide a navigation menu on scroll down with CSS and JavaScript, you should have basic knowledge of JavaScript conditional statements and CSS. We will create the navigation menu using HTML, style it with CSS, and use JavaScript to hide the navigation menu while scrolling down. Our task is to hide the navigation menu while scrolling down and show it when scrolling up. This creates a smooth user experience by maximizing content space while keeping navigation accessible. Creating Structure of Navigation Menu Using HTML Styling the Navigation Menu Using ...

Read More

Validating a file size in JavaScript while uploading

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

File size validation is essential for web applications to prevent users from uploading files that are too large for your server or application limits. JavaScript provides built-in methods to check file size before upload begins. How File Size Validation Works When a user selects a file using an HTML file input, JavaScript can access the file's properties through the files property. The size property returns the file size in bytes, which we can then validate against our requirements. Basic File Size Validation ...

Read More

JavaScript recursive loop to sum all integers from nested array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 482 Views

JavaScript recursive functions can process nested arrays by calling themselves repeatedly to handle arrays within arrays. This technique is essential for working with complex data structures of unknown depth. Example: Basic Recursive Sum function sumOfTotalArray(numberArray) { var total = 0; for (var index = 0; index < numberArray.length; index++) { if (numberArray[index] instanceof Array) { total = total + sumOfTotalArray(numberArray[index]); } ...

Read More

Sorting an associative array in ascending order - JavaScript

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

In JavaScript, you can sort an array of objects (associative array) in ascending order using the sort() method with a custom comparison function. Suppose we have an array of objects like this: const people = [ {"id":1, "name":"Andrew", "age":30, "gender":"m", "category":"G"}, {"id":2, "name":"Brandon", "age":25, "gender":"m", "category":"G"}, {"id":3, "name":"Christine", "age":20, "gender":"m", "category":"G"}, {"id":4, "name":"Elena", "age":29, "gender":"W", "category":"M"} ]; We need to sort this array by the age property in ascending order. The expected output should be: [ ...

Read More

How to compare only date part without comparing time in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 7K+ Views

While developing applications, you often need to compare only the date parts of two Date objects, ignoring the time components. For example, in a subscription system, you might want to check if a user's payment was made on or before the subscription deadline, regardless of what time the payment was processed. In this tutorial, we will learn to compare only the date part without comparing the time in JavaScript. Using the setHours() Method The most straightforward approach is to set the time components (hours, minutes, seconds, milliseconds) to zero for both date objects. This ensures that when ...

Read More

How -Infinity is converted to Number in JavaScript?

Monica Mona
Monica Mona
Updated on 15-Mar-2026 300 Views

In JavaScript, -Infinity is a special numeric value representing negative infinity. When converted using the Number() method, it remains -Infinity since it's already a valid number type. Understanding -Infinity -Infinity is a built-in JavaScript constant that represents the mathematical concept of negative infinity. It's already of type "number", so converting it with Number() simply returns the same value. -Infinity Conversion Converting -Infinity to Number var myVal = -Infinity; ...

Read More
Showing 18231–18240 of 61,297 articles
Advertisements