Javascript Articles

Page 326 of 534

How to set all the border left properties in one declaration with JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 153 Views

The borderLeft property in JavaScript allows you to set all the left border properties (width, style, and color) in a single declaration. This is more convenient than setting borderLeftWidth, borderLeftStyle, and borderLeftColor individually. Syntax element.style.borderLeft = "width style color"; Parameters width: Border thickness (e.g., "thin", "medium", "thick", or pixel values like "5px") style: Border style (e.g., "solid", "dashed", "dotted", "double") color: Border color (e.g., color names, hex codes, rgb values) Example ...

Read More

Compute the sum of elements of an array which can be null or undefined JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 844 Views

When working with arrays containing numbers, null, and undefined values, we need to compute sums while treating these falsy values as zero. This is a common scenario when processing data from APIs or user inputs. Let's say we have an array of arrays, each containing some numbers along with some undefined and null values. We need to create a new array that contains the sum of each corresponding sub-array elements, treating undefined and null as 0. Following is the sample array: const arr = [[ 12, 56, undefined, 5 ], [ ...

Read More

With JavaScript how to change the width of a table border?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 1K+ Views

To change the width of a table border in JavaScript, use the DOM border property or the more specific borderWidth property. This allows you to dynamically modify table borders after the page loads. Syntax element.style.border = "width style color"; element.style.borderWidth = "width"; Example: Changing Table Border Width function borderFunc(x) { document.getElementById(x).style.border = "5px dashed blue"; ...

Read More

How to get the product of two integers without using * JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 380 Views

We are required to write a function that takes in two numbers and returns their product, but without using the (*) operator. Method 1: Using Division Operator We know that multiplication and division are inverse operations, so if we divide a number by another number's inverse, it's the same as multiplying the two numbers. The mathematical concept: a × b = a ÷ (1 ÷ b) const a = 20, b = 45; const product = (a, b) => a / (1 / b); console.log(product(a, b)); 900 Method 2: Using ...

Read More

How to set the color of an elements border with JavaScript?

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

In this tutorial, we will learn how to set the color of an element's border with JavaScript. The border is the outline of an HTML element. The border can be styled differently with different types of border properties. To set the color of the border of an element with JavaScript, we have the style borderColor property. Using the Style borderColor Property In JavaScript, the style borderColor property of an element is used to set the color of the border of an element. To set the color of the border of an element, we first need to get ...

Read More

How to set the right position of a positioned element with JavaScript?

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

In this tutorial, we shall learn to set the right position of a positioned element with JavaScript. What is a positioned element? The available position values in CSS are relative, absolute, fixed, or static. The static position is the default position value. Static elements are in the document order. A positioned element's position is based on its properties like the top, right, bottom, and left. We must set the position in every direction to align the elements as required. Here we are going to see the right position property. Using the right Property With this ...

Read More

How to set the painting area of the background with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 376 Views

In this tutorial, we will learn how to set the painting area of the background with JavaScript using the backgroundClip property. The background-clip CSS property defines how far a background (color or image) extends within an element. It specifies whether the background extends beneath the border-box, padding-box, or content-box of an element. Understanding background-clip Property The background-clip property accepts three main values: border-box - Background extends to the outer edge of the border (default) padding-box - Background extends to the outer edge of the padding content-box ...

Read More

Replace a letter with its alphabet position JavaScript

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

We are required to write a function that takes in a string, trims it off any whitespaces, converts it to lowercase and returns an array of numbers describing corresponding characters positions in the english alphabets, any whitespace or special character within the string should be ignored. Problem Example Input → 'Hello world!' Output → [8, 5, 12, 12, 15, 23, 15, 18, 12, 4] How It Works The algorithm processes each character by: Converting to lowercase to handle both cases uniformly Getting ASCII code using charCodeAt() ...

Read More

How to set the style of the bottom border with JavaScript?

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

To set the style of the bottom border, use the JavaScript borderBottomStyle property. It allows you to add a bottom border with different styles like solid, dashed, dotted, and more. Syntax element.style.borderBottomStyle = "value"; Common Border Style Values Value Description solid Creates a solid line dashed Creates a dashed line dotted Creates a dotted line double Creates a double line none Removes the border Example The following example demonstrates how to set different bottom border styles on button ...

Read More

How to add a character to the beginning of every word in a string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 938 Views

We need to write a function that takes two strings and returns a new string with the second argument prepended to every word of the first string. For example: Input → 'hello stranger, how are you', '@@' Output → '@@hello @@stranger, @@how @@are @@you' If the second argument is not provided, we'll use '#' as the default character. Solution Using split() and map() The most straightforward approach is to split the string into words, prepend the character to each word, and join them back: const str = 'hello stranger, how are ...

Read More
Showing 3251–3260 of 5,340 articles
« Prev 1 324 325 326 327 328 534 Next »
Advertisements