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
Javascript Articles
Page 13 of 534
JavaScript Program to Find the subarray with least average
We are going to write a program that will find the subarray with the least average. To do this, we will iterate through the array and keep track of the current subarray and its sum. For each element, we will calculate the average of the current subarray and compare it with the minimum average we have seen so far. If it is lower, we will update the minimum average and the start and end indices of the subarray. At the end of the iteration, we will return the subarray with the least average. Approach To find the subarray ...
Read MoreJavaScript Program to Form coils in a matrix
We will be using JavaScript to form coils in a matrix. The process involves manipulating the elements of the matrix to create a spiral pattern. This can be achieved by changing the direction of traversal, keeping track of the visited elements, and adjusting the indices accordingly. Approach One approach to form coils in a matrix using JavaScript would be the following − Define the size of the matrix. Initialize the matrix with zeros. Use nested loops to traverse the matrix and change the values of specific cells ...
Read MoreExplain the MUL() function in JavaScript
In this tutorial, we will learn to implement the MUL() function in JavaScript. This function demonstrates multiplication using nested functions, which create closures that maintain access to outer function variables. The MUL() function showcases JavaScript's first-class function nature, where functions can be returned from other functions. There are two ways to implement the MUL() function using nested functions: Using nested functions with names Using function currying with anonymous functions Using Nested Functions With Names In JavaScript, we can use nested functions to create a multiplication function that takes arguments one at a time. Each ...
Read MoreExplosion Animation in Canvas
In this tutorial, we will learn to create an explosion animation effect using canvas in HTML. Canvas provides a powerful way to draw dynamic graphics and animations on web pages. We'll explore two different approaches: a basic particle explosion and an interactive mouse-triggered explosion effect. Basic Particle Explosion This creates an explosion of 50 randomly colored particles that originate from the center of the canvas and move in random directions. How It Works The animation works by creating particle objects with position, velocity, and color properties. Each frame, we update particle positions and redraw them ...
Read MoreFastest way to convert JavaScript NodeList to Array
In this tutorial, we will learn the fastest way to convert JavaScript NodeList to Array. NodeList is a similar structure to an array; it is a collection of DOM (Document Object Model) elements. However, array methods like 'map()', 'filter()', and 'slice()' cannot be used on NodeList objects. There are several ways to convert NodeList to Array, but this task can be done faster using these approaches: Using Array.from() function (Recommended) Using spread operator (...) By iterating with for loop Using Array.from() (Recommended) The Array.from() method ...
Read MoreHow to change Input box borders after filling the box using JavaScript?
The style.border property is used to change an element's border styling in JavaScript. It allows you to modify the border-color, border-style, and border-width properties dynamically. This is particularly useful for providing visual feedback when users interact with form elements. We use the onchange event to trigger border changes after filling input boxes. The onchange event occurs when the value of an HTML element changes and the element loses focus. This differs from oninput, which fires immediately as the user types. The onchange event works with various form elements including text inputs, radio buttons, checkboxes, and select dropdowns. It's ...
Read MoreHow to change font style using drop-down list in JavaScript?
In JavaScript, you can change the font style of text elements using a dropdown list by combining HTML select elements with the style.fontFamily property. This creates an interactive way for users to change text appearance dynamically. A dropdown list (select element) allows users to choose from multiple font options. When a selection is made, JavaScript captures the change event and applies the selected font to target elements. Syntax The basic syntax for changing font family using JavaScript: element.style.fontFamily = "fontName"; HTML select element with options: Arial ...
Read MoreHow to change the font-weight of a text using JavaScript?
Using JavaScript is one of the most effective ways to dynamically change the font-weight of any text on your webpage. Font weight refers to the boldness or thinness of characters, ranging from 100 (thin) to 900 (black/heavy). In this article, we will explore how to change font-weight using JavaScript for both single and multiple elements. Using the Style fontWeight Property The style.fontWeight property allows us to change the font weight of individual HTML elements. This property accepts both numeric values and keyword values. Syntax document.getElementById("elementId").style.fontWeight = "normal|lighter|bold|bolder|100-900|initial|inherit"; You can assign numeric values (100-900) ...
Read MoreHow to change the href value of tag after clicking on button using JavaScript?
The href attribute specifies the link's destination, which can be a URL or an anchor point within the same document. Changing the href attribute value allows us to dynamically update the destination of the link, which can be useful in creating interactive web applications. The tag (anchor tag) is used to create hyperlinks in HTML, linking to other web pages or specific locations within the same document. By combining JavaScript with HTML elements, we can modify these links dynamically based on user interactions. In this article, we'll explore how to change the href value of an anchor ...
Read MoreExplain Chosen and Select2 with Examples
Select2 and Chosen are popular jQuery plugins that enhance HTML select boxes with improved styling, search capabilities, and user-friendly features. Both plugins work with single and multiple select elements, making form interactions more intuitive. Chosen Plugin Chosen is a JavaScript plugin that transforms standard select boxes into user-friendly dropdown interfaces. It's available for both jQuery and Prototype frameworks. Key Features of Chosen User-friendly Interface Users can search by typing instead of scrolling through long lists. Matching is instant, and non-matching options are filtered out automatically. Progressive Enhancement Chosen gracefully degrades to standard HTML select elements ...
Read More