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 338 of 534
How to set the length of the item relative to the rest with JavaScript?
Use the flex property in JavaScript to set the length of flex items relative to each other. The flex property controls how much space a flex item should take up within a flex container. Syntax element.style.flex = "value"; The flex value can be a number (flex-grow), or a combination of flex-grow, flex-shrink, and flex-basis values. Example #box { ...
Read MoreHow to set the left margin of an element with JavaScript?
In this tutorial, we will learn how to set the left margin of an element with JavaScript. Margin is the space around an element outside its border. The margin of an element can be on all sides, such as: left, right, top, and bottom. Use the marginLeft property in JavaScript to set the left margin. In this tutorial, we will discuss two approaches to setting the left margin − Using the marginLeft property Using the setProperty method Using the marginLeft property to set the left margin of an ...
Read MoreHow to create or reset counters with JavaScript?
CSS counters provide a way to automatically number elements on a webpage. In JavaScript, you can create or reset counters using the counterReset property to control counter initialization and reset points. How CSS Counters Work CSS counters use three main properties: counter-reset - Creates or resets a counter counter-increment - Increments the counter value counter() - Displays the counter value in content Basic Counter Example body { ...
Read MoreEquivalent of Ruby's each cons in JavaScript
Ruby's each_cons() method iterates through consecutive N elements of an enumerable, creating subarrays of fixed size. JavaScript doesn't have this built-in, but we can implement it using Array prototype extension. Understanding each_cons Behavior The each_cons(n) function creates sliding windows of size n from an array. For each starting position, it takes n consecutive elements until there aren't enough remaining elements. const arr = [1, 2, 3, 4, 5]; // With n=2: creates pairs starting from each position // Result: [[1, 2], [2, 3], [3, 4], [4, 5]] // With n=3: creates triplets starting from ...
Read MoreHow to set the initial length of a flexible item with JavaScript?
In this tutorial, we will learn how to set the initial length of a flexible item with JavaScript. Flexbox is a one-dimensional layout model that distributes space among items in an interface and provides flexible item alignment properties. It creates flexible items. Use the flexBasis property in JavaScript to set the initial length of a flexible item. In this tutorial, we will see two approaches to setting the initial length of a flexible item: Using the property style.flexBasis Using the method style.setProperty Using the style.flexBasis Property The style flexBasis is a flexbox property ...
Read MoreHow to set the type of cursor to display for the mouse pointer with JavaScript?
In this tutorial, we will learn to set the type of cursor for the mouse pointer with JavaScript. To set the type of cursor, use the cursor property in JavaScript. It allows you to change the cursor on the button click. We can even change the type of cursor by using JavaScript. Different types of cursors have different meanings. There are many styles of cursors that can use on our webpage. Let us look at how to set the type of cursor to display for the mouse pointer with JavaScript. Using the Style cursor Property The ...
Read MoreHow to make flexible items display in columns with JavaScript?
The flexFlow property in CSS controls how flexible items are arranged within a flex container. To display items in columns using JavaScript, you can modify this property dynamically. Understanding flexFlow The flexFlow property is a shorthand that combines flex-direction and flex-wrap. For column layout, use column for direction and nowrap or wrap for wrapping behavior. Example Here's how to change flexible items from row to column layout using JavaScript: #box { ...
Read MoreHow to set an element's display type with JavaScript?
In JavaScript, you can control an element's visibility and layout behavior by modifying its display property through the DOM. This property accepts various values like block, inline, flex, or none to hide elements completely. Syntax element.style.display = "value"; Where value can be block, inline, flex, grid, none, or other CSS display values. Example: Hiding an Element You can try to run the following code to set an element's display type with JavaScript: ...
Read MoreJavaScript function to accept a string and mirrors its alphabet
We need to write a function that accepts a string and mirrors its alphabet. This means each letter is replaced with its counterpart from the opposite end of the alphabet. If the input is 'abcd' The output should be 'zyxw' The function maps every character to the letter that is (26 - N) positions away from it, where N is the 1-based index of that alphabet (like 5 for 'e' and 10 for 'j'). How It Works We use the String.prototype.replace() method to match all English alphabets regardless of case. For each letter: ...
Read MoreHow to know whether the border and background of empty cells are hidden or not with JavaScript?
In this tutorial, we will learn how to detect whether empty table cells have hidden borders and backgrounds using JavaScript. This is useful when working with dynamic tables where some cells may be empty. The emptyCells CSS property controls whether borders and backgrounds are displayed for empty table cells. JavaScript provides methods to check and modify this behavior programmatically. Understanding Empty Cells Empty table cells can either show their borders and backgrounds or hide them completely. The empty-cells CSS property has two values: show - Display borders and backgrounds for empty cells (default) hide - ...
Read More