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 332 of 534
How to set the stack order of a positioned element in JavaScript?
In this tutorial, we shall learn to set the stack order of a positioned element in JavaScript. To set the stack order, we can use the style zIndex property. Let's first check what the stack order is. The stack order says the order in which the DOM elements are displayed. This is the element's position on the z-axis. Now, what is a positioned element? A positioned element has relative, absolute, fixed, or static positions. Why do we need to go for the stack order? Elements might overlap and look clumsy when positioned; therefore, we go for the ...
Read MoreHow to set the style of an element's border with JavaScript?
In this tutorial, we shall learn to set the style of an element's border with JavaScript. To set the style of an element's border, use the borderStyle property in JavaScript. Let us discuss the borderStyle property available in detail. Using the borderStyle Property With the borderStyle property, we can set or return the style of an element's border. Syntax Following is the syntax to use the borderStyle property to set the style of an element's border with JavaScript − object.style.borderStyle = style; This syntax allows us to set the required border ...
Read MoreHow to allow long and unbreakable words to be broken and wrap to the next line in JavaScript?
Use the wordWrap CSS property in JavaScript to allow long and unbreakable words to be broken and wrap to the next line. This property is especially useful when dealing with long URLs, email addresses, or continuous text that would otherwise overflow their container. Syntax element.style.wordWrap = "break-word"; wordWrap Property Values Value Description normal Default behavior - only ...
Read MoreVerification if a number is Palindrome in JavaScript
A palindrome number reads the same forwards and backwards. In JavaScript, we can check if a number is palindrome without converting it to a string by mathematically extracting and comparing digits. Palindrome numbers are those numbers which read the same from both backward and forward. For example: 121 343 12321 Algorithm Approach The algorithm works by: Finding a factor to extract the first digit Comparing first and last digits Removing both digits and repeating until all digits are checked Example const isPalindrome = (num) => { ...
Read MoreHow to set or return the number of columns an element should be divided into with JavaScript?
In JavaScript, the columnCount property allows you to divide an element's content into multiple columns. This CSS property can be set and retrieved using JavaScript's style object. Syntax // Set column count element.style.columnCount = "number"; // Get column count let count = element.style.columnCount; Parameters The columnCount property accepts: number - The number of columns (e.g., "2", "3", "4") "auto" - Browser determines column count automatically "initial" - Sets to default value Example: Setting Column Count Click the button to divide the text into 4 columns: ...
Read MoreSum of even numbers up to using recursive function in JavaScript
We have to write a recursive function that takes in a number n and returns the sum of all even numbers up to n. A recursive function calls itself with modified parameters until it reaches a base case. For summing even numbers, we'll start from the largest even number ≤ n and work our way down. How It Works The algorithm follows these steps: If the input number is odd, we adjust it to the nearest even number below it Add the current even number to the sum and recursively call with the next smaller ...
Read MoreCalculate text width with JavaScript
To calculate text width, we can use the measureText() method in JavaScript. In canvas, the measureText() method is used to measure width of the text content. This means we can pass text to this canvas method and then call that method to measure the text. It will return an object that contains information about the measured text. Sometimes, width may be a float value; hence the Math.ceil() method is used to round the value and returns an integer. Syntax Following is the syntax of the method used to calculate the text width: const text = ...
Read MoreGet unique item from two different array in JavaScript
We are required to make a function that accepts an array of arrays, and returns a new array with all elements present in the original array of arrays but remove the duplicate items. For example − If the input is − const arr = [ [12, 45, 65, 76, 76, 87, 98], [54, 65, 98, 23, 78, 9, 1, 3], [87, 98, 3, 2, 123, 877, 22, 5, 23, 67] ]; Then the output should be single array of unique elements like this − ...
Read MoreHow to print content of JavaScript object?
In this tutorial, we will learn to print the content of a JavaScript object. Objects are similar to variables, but they can contain many values. Javascript object values are written as key: value pairs, and each pair is separated by commas. It is used to access data from databases or any other sources. Following are the ways to print the content of JavaScript objects − Using the JSON.stringify() Method Using Object.values() Using a for-in loop Using JSON.stringify() Method The JSON.stringify() method converts JavaScript objects ...
Read MoreHow to replace all dots in a string using JavaScript?
In this tutorial, we will explore different ways to replace all dots in a string using JavaScript. While it's possible to remove all occurrences of dots manually with a for loop, JavaScript provides built-in methods that make this task much simpler. The two most popular methods for replacing all dots in a string are: Using the replaceAll() Method The replaceAll() method replaces all occurrences of a specified pattern with a replacement string. This is the most straightforward approach for replacing all dots. Syntax string.replaceAll(searchValue, replaceValue) Parameters searchValue ...
Read More