Javascript Articles

Page 325 of 534

How to set the starting position of a background image in JavaScript DOM?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 568 Views

To set the starting position of a background image in JavaScript, use the backgroundPosition property. This property allows you to specify where the background image should be positioned within its container. Syntax element.style.backgroundPosition = "value"; Position Values The backgroundPosition property accepts various values: Keywords: top, bottom, left, right, center Percentages: 50% 25% (horizontal vertical) Pixels: 10px 20px (horizontal vertical) Mixed: left 50px, center top Example: Setting Background Position body { ...

Read More

Completely removing duplicate items from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 355 Views

We are required to write a function that takes in an array and returns a new array that have all duplicate values removed from it. The values that appeared more than once in the original array should not even appear for once in the new array. For example, if the input is: const arr = [23, 545, 43, 232, 32, 43, 23, 43]; The output should be: [545, 232, 32] Understanding indexOf() vs lastIndexOf() Array.prototype.indexOf() → Returns the index of first occurrence of searched ...

Read More

How to style background image to no repeat with JavaScript DOM?

Abhishek
Abhishek
Updated on 15-Mar-2026 3K+ Views

In this tutorial, we will learn to style the background image to no repeat with JavaScript DOM. To style the background image to no repeat with JavaScript, use the backgroundRepeat property. It allows you to set whether the background image repeats or not on a page. The use of images in the background really makes the page attractive. But before using the image in the background, one must completely understand the properties used to set the images as the background. Otherwise, it will create problems like not showing the full image in the background, repeating the image horizontally or ...

Read More

How to set the color of the top border with JavaScript?

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

In this tutorial, we will learn how to set the color of the top border with JavaScript. The HTML element's outline is called the border. The border of an element can have multiple colors on each side. Different properties and methods are used to color each side of the border. To set the color of the top border with JavaScript, we have different ways − Using the style.borderTopColor Property Using the style.borderColor Property Using the style.borderTopColor Property The style.borderTopColor property of an element in JavaScript is used to ...

Read More

How to set the shape of the border of the top-left corner with JavaScript?

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

In this tutorial, we will learn to set the radius of the top-left corner of the border using JavaScript DOM. To set the shape of the border of the top-left corner in JavaScript, use the borderTopLeftRadius property. Set the border radius using this property. We apply borders on a webpage many times. Generally, it is used to display the importance of an element or a difference between the sections. We can create a table in a webpage by using HTML. It is a simple table that does not attract the user. So, we use CSS to design the table ...

Read More

How to set border width, border style, and border color in one declaration with JavaScript?

Paul Richard
Paul Richard
Updated on 15-Mar-2026 1K+ Views

To set the border width, style, and color in a single declaration, use the border property in JavaScript. This property accepts a shorthand value that combines all three border properties. Syntax element.style.border = "width style color"; The order is: width, style, color. You can also specify individual sides using borderTop, borderRight, borderBottom, or borderLeft. Example: Setting Border with Button Click Set Border Demo Text ...

Read More

Find duplicate element in a progression of first n terms JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 203 Views

When you have an array of first n natural numbers with one duplicate element, finding the duplicate efficiently is a common programming challenge. We'll explore two mathematical approaches that solve this in linear time. Method 1: Using Array.prototype.reduce() This approach uses a mathematical trick with the reduce function to find the duplicate in a single pass: const arr = [2, 3, 1, 2]; const duplicate = a => a.reduce((acc, val, ind) => val + acc - (ind + 1)) + a.length - 1; console.log(duplicate(arr)); 2 How the Reduce Method Works ...

Read More

Set whether the table border should be collapsed into a single border or not with JavaScript?

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

In this tutorial, let us look at how to set whether the table border should collapse into a single table border or not with JavaScript. We can use the borderCollapse property in JavaScript to accomplish this. This property controls how table borders are displayed - either as separate borders for each cell or collapsed into a single unified border. Using the Style borderCollapse Property The borderCollapse property defines whether the table border should collapse into a single table border or separate into a double table border. The value 'separate' is the default. The borderCollapse is a read-and-write ...

Read More

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

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

In this tutorial, we shall learn to set the width of the bottom border with JavaScript. To set the width of the bottom border, we can use the borderBottomWidth property in JavaScript. It allows you to change the width. Let us discuss our topic in brief. Using the borderBottomWidth Property With this property, we can set or return the width of an element's bottom border. Width is a floating point number with either a relative units designator (cm, mm, in, pt, or pc) or an absolute units designator (em, ex, or px). Syntax Following is ...

Read More

How to use JavaScript DOM to change the padding of a table?

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

In this tutorial, we learn to use JavaScript DOM to change the padding of a table. To change the padding of a table, use the DOM padding property. The HTML table is used to display relational data on the user screen. We can easily show related or dependent data to the user and user can easily understand and determine the characteristics of the data with help of table. But, while we are showing the relational data to the user in the form of table, we need to make sure that the table is well structured and looking good according ...

Read More
Showing 3241–3250 of 5,340 articles
« Prev 1 323 324 325 326 327 534 Next »
Advertisements