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 329 of 534
How to set the top padding of an element with JavaScript?
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 MoreHow to make a function that returns the factorial of each integer in an array JavaScript
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 MoreHow to set the bottom position of 3D elements with JavaScript?
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 MoreHow to set the style of the line in a text decoration with JavaScript?
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 MoreHow to set the indentation of the first line of text with JavaScript?
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 MoreWhat is to be done when text overflows the containing element with JavaScript?
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 MoreFind n highest values in an object JavaScript
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 MoreHow to set the capitalization of a text with JavaScript?
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 MoreHow to separate alphabets and numbers from an array using JavaScript
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 MoreHow to set whether the text of an element can be selected or not with JavaScript?
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