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 188 of 589
How to Iterate Elements by ClassName in JavaScript?
To iterate elements by className in JavaScript, we use the getElementsByClassName() method. This method returns a live HTMLCollection of all elements in the document with the specified class name. In this article, we'll explore different approaches to iterate through elements that share the same class name, using practical examples with three div elements. getElementsByClassName() Overview The getElementsByClassName() method returns an HTMLCollection, which is array-like but not a true array. This collection updates automatically when elements are added or removed from the DOM. Approaches to Iterate Elements by ClassName Here are the most effective approaches to ...
Read MoreConvert HH:MM:SS to seconds with JavaScript?
To convert HH:MM:SS to seconds with JavaScript, we use simple arithmetic operations like multiplication and addition. We split the time string and convert each component to seconds using the formula: hours × 3600 + minutes × 60 + seconds. In this article, we are given a time in HH:MM:SS format and our task is to convert it to total seconds using JavaScript. Steps to Convert HH:MM:SS to Seconds Use the split() function to separate hours, minutes, and seconds by colon delimiter. Convert hours to seconds by multiplying by 3600 ...
Read MoreJavaScript Create Submit button for form submission and another button to clear input
Form handling is a fundamental aspect of web development. A Submit button sends the form data for processing, while a Clear button allows users to reset or empty the form inputs. This functionality enhances user experience and ensures proper data entry. In this tutorial, we'll learn how to create a form with a Submit button for handling submissions and a Clear button for resetting inputs using JavaScript. We'll also handle the actions triggered by these buttons effectively. Creating a Submit Button for Form Submission ...
Read MoreJavaScript filter array by multiple strings
Filtering an array by multiple strings in JavaScript involves identifying elements that match any string from a given list. This is commonly used in search filters, dynamic matching, or data processing tasks. JavaScript provides simple tools like the filter method and techniques such as includes for exact matches or regular expressions for pattern-based matching. These approaches help efficiently narrow down arrays based on specific criteria. Approaches to Filter Array by Multiple Strings Here are three effective approaches to filter an array by multiple strings in JavaScript: Using filter with includes (Recommended) ...
Read MoreJavaScript tracking the differences between elements in an array
Tracking differences between elements in an array is a fundamental task in data analysis and software development. Whether you're analyzing trends in numerical data, measuring changes over time, or debugging an application's behavior, calculating these differences can provide valuable insights. In JavaScript, this task is often approached using various techniques, including loops and modern functional programming methods like the map() function. Here are two methods to calculate differences between elements in an array: Iterative Loop and Functional Programming using the map. Problem Statement We are given an array of Number literals, and we are required to write ...
Read MoreJavaScript example for Capturing mouse positions after every given interval
In this article, we will demonstrate how to capture the mouse position in JavaScript at regular intervals and log or use this data for various purposes. Capturing mouse positions after every given interval refers to a program or functionality where the current position of the mouse pointer is tracked at regular time intervals. This can be useful in scenarios like debugging, interactive applications, or visualizing user movement on a web page. Use Cases Imagine you want to monitor user activity on a web page and record the mouse position every second. This can be useful for: ...
Read MoreJavaScript - Redirect a URL
In JavaScript, redirecting a user from one URL to another is a straightforward task. There are multiple ways to achieve this, but we'll focus on two of the most common and effective methods: window.location.href and window.location.replace(). Both are widely used for different purposes, and understanding when to use each one can help improve user navigation on your site. Approaches to Redirect a URL in JavaScript Following are the different approaches to redirect a URL: Using window.location.href Using window.location.replace() Redirect a URL Using window.location.href Property The ...
Read MoreJavaScript get row count of an HTML table
Tables are a common way to organize and display data in HTML. If you're working with tables dynamically in JavaScript, you might need to count the rows in an HTML table for various purposes, such as validation, manipulation, or displaying statistics. In this article, we will demonstrate how to retrieve the row count of an HTML table using JavaScript. We will use the rows property to access the row count through rows.length, and also show how to count rows in specific table sections like . Understanding the rows Property The rows property in JavaScript provides access to ...
Read MoreJavaScript remove random item from array and then remove it from array until array is empty
We are given an array of string/number literals. We are required to create a function removeRandom() that takes in the array, recursively removes one random item from it, and simultaneously prints it until the array contains items. This can be done by creating a random number using Math.random(), removing the item at that index using Array.prototype.splice(), and printing it until the length of the array shrinks to 0. Approaches to Remove Random Items from Array Following are the different approaches to removing the random item from an array and then removing it from the array until the ...
Read MoreJavaScript program to access browsing history
In this article, we will learn to access browsing history using JavaScript. In web development, accessing a user's browsing history can improve user experience and provide personalized content. However, due to privacy concerns and security reasons, modern web browsers limit the amount of browsing history accessible via JavaScript. What is Browsing History? Browsing history refers to the list of web pages that a user has visited over a while. Browsers typically store this data locally, allowing users to navigate back and forth through the pages they've visited. The window.history Object In JavaScript, the window.history object allows ...
Read More