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
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to stop dragend's default behavior in drag and drop?
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 MoreHTML5 & JavaScript: resolution or size of
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 MoreRemoving a node in a Javascript Tree
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 MoreHow to select a radio button by default in JavaScript?
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 MoreHow to hide a navigation menu on scroll down with CSS and JavaScript?
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 MoreValidating a file size in JavaScript while uploading
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 MoreJavaScript recursive loop to sum all integers from nested array?
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 MoreSorting an associative array in ascending order - JavaScript
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 MoreHow to compare only date part without comparing time in JavaScript?
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 MoreHow -Infinity is converted to Number in JavaScript?
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