Javascript Articles

Page 329 of 534

How to set the top padding of an element with JavaScript?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 679 Views

Use the paddingTop property in JavaScript to set the top padding of an element. This property allows you to dynamically modify the spacing between an element's content and its top border. Syntax element.style.paddingTop = "value"; Where value can be specified in pixels (px), percentages (%), or other CSS units. Example #box { border: 2px solid #FF0000; ...

Read More

How to make a function that returns the factorial of each integer in an array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 751 Views

We are here required to write a JavaScript function that takes in an array of numbers and returns another array with the factorial of corresponding elements of the array. We will first write a recursive method that takes in a number and returns its factorial and then we will iterate over the array, calculating the factorial of each element of array and then finally we will return the new array of factorials. Therefore, let's write the code for this Creating the Factorial Function First, we'll create a recursive function to calculate the factorial of a single number: ...

Read More

How to set the bottom position of 3D elements with JavaScript?

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

In this tutorial, we will learn how to set the bottom position of 3D elements with JavaScript. In a web page, handling a 3D element can be tricky. Using JavaScript, we had to set the top, bottom, sides, etc. To set the bottom position of 3D elements, we use the perspectiveOrigin property of an element's style object. Using style.perspectiveOrigin Property In JavaScript, the style.perspectiveOrigin property is used to set the bottom position or base position of a 3D element. Firstly, we get the element object using the document.getElementById() method and then set the style.perspectiveOrigin property. Syntax ...

Read More

How to set the style of the line in a text decoration with JavaScript?

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

In this tutorial, we shall learn to set the style of the line in a text decoration with JavaScript. To set the style of the line in JavaScript, use the textDecorationStyle property. You can set underline, double, or overline, etc. for the line style. Using the Style textDecorationStyle Property We can set or return the line style in a text decoration with this property. The major browsers support this property. Firefox adds support with an alternate property named MozTextDecorationStyle. Syntax object.style.textDecorationStyle = "solid" | "double" | "dotted" | "dashed" | "wavy" | "initial" | "inherit"; ...

Read More

How to set the indentation of the first line of text with JavaScript?

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

In this tutorial, we will learn how to set the indentation of the first line of text with JavaScript. The indentation of the first line of a text is a common way to start a new paragraph. To set the indentation, use the textIndent property. To set the indentation of the first line of text with JavaScript, we will discuss two different ways − Using the style.textIndent Property Using the style.setProperty Method Using the style.textIndent Property The style.textIndent property of an element is used to set the ...

Read More

What is to be done when text overflows the containing element with JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 154 Views

When text overflows its container, JavaScript can help control the display behavior using the textOverflow property. This property works with CSS to handle overflow gracefully by adding ellipses or clipping the text. CSS Requirements For textOverflow to work properly, the element must have these CSS properties: overflow: hidden - Hide overflowing content white-space: nowrap - Prevent text wrapping Fixed width - Constrain the container size JavaScript textOverflow Values The textOverflow property accepts these values: "clip" - Cut off text at container edge "ellipsis" - Show "..." where text is cut "visible" ...

Read More

Find n highest values in an object JavaScript

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

Let's say, we have an object that describes various qualities of a football player like this − const qualities = { defence: 82, attack: 92, heading: 91, pace: 96, dribbling: 88, tenacity: 97, vision: 91, passing: 95, shooting: 90 }; We wish to write a function that takes in such object and a number n (n ≤ no. of keys ...

Read More

How to set the capitalization of a text with JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 283 Views

To set the capitalization, use the textTransform property in JavaScript. Set it to capitalize, if you want the first letter of every word to be a capital letter. Syntax element.style.textTransform = "value"; The textTransform property accepts these values: capitalize - Capitalizes the first letter of each word uppercase - Converts all text to uppercase lowercase - Converts all text to lowercase none - Removes any text transformation Example: Capitalizing Text You can try to run the following code to capitalize text with JavaScript: ...

Read More

How to separate alphabets and numbers from an array using JavaScript

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

We have an array that contains some number literals and some string literals mixed, and we are required to write a sorting function that separates the two and the two types should also be sorted within. This approach uses a custom comparator function with JavaScript's sort() method to first separate numbers from strings, then sort each type individually. Using Custom Sort Comparator The code for this sorting function will be: const arr = [1, 5, 'fd', 6, 'as', 'a', 'cx', 43, 's', 51, 7]; const sorter = (a, b) => { ...

Read More

How to set whether the text of an element can be selected or not with JavaScript?

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

In this tutorial, we will learn to set whether the text of an element can be selected or not with JavaScript. Use the userSelect property in JavaScript to enable or disable a text selection. For Firefox, use the MozUserSelect property and set it to none, to disable the selection. The CSS user-select property can set the text on a web page as selectable or nonselectable. But, sometimes, we must restrict the selection to a triggered event or a condition. Then, we can use the JavaScript DOM that provides nearly all CSS properties. So, let us look at how ...

Read More
Showing 3281–3290 of 5,340 articles
« Prev 1 327 328 329 330 331 534 Next »
Advertisements