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 330 of 534
How to set the vertical alignment of the content in an element with JavaScript?
In this tutorial, we will learn how to set the vertical alignment of the content in an element using JavaScript. The verticalAlign property of the HTML DOM Style object controls how content is positioned vertically within inline, inline-block, and table-cell elements. This property is particularly useful for aligning text within table cells or positioning inline elements relative to their surrounding content. Note that vertical-align only applies to inline, inline-block, and table-cell elements; it cannot be used to align block-level elements. Syntax element.style.verticalAlign = "value"; Common values include: top, middle, bottom, baseline, text-top, and ...
Read MoreHow to set the right padding of an element with JavaScript?
In this tutorial, we will learn how to set the right padding of an element with JavaScript. First, let's try to understand what padding means; padding is simply an extra space between a page's border and our content. The gap between them increases as the value of padding increases. Padding is similar to the margin; padding is distinct from the margin because padding adds space between the border and content, whereas margin is used to add space around the edge. While padding can be done on all sides, i.e., Top, Bottom, Left, and Right in the following lines, ...
Read MorePositive integer square array JavaScript
In JavaScript, we often need to filter arrays to extract specific types of numbers and perform operations on them. This example demonstrates how to find positive integers in an array and return the sum of their squares. Problem Statement Given an array containing various numbers (positive, negative, decimals, and integers), we need to write a function that returns the sum of squares of all positive integers only. Solution We'll use the reduce() method to iterate through the array and accumulate the sum of squares for positive integers: const arr = [1, -4, 6.1, 0.1, ...
Read MoreHow nested elements are rendered in 3D space with JavaScript?
This tutorial demonstrates how to control the 3D rendering of nested HTML elements using JavaScript and the CSS transform-style property. The transform-style property determines whether child elements are positioned in 3D space or flattened to their parent's plane. When working with 3D transformations like rotateY(), rotateX(), or rotateZ(), this property controls how nested elements maintain their 3D positioning relative to their parent container. Transform-Style Property Values The transform-style property accepts two main values: flat (default): Child elements are flattened to the parent's plane, losing their 3D positioning preserve-3d: Child elements maintain their 3D positioning in ...
Read MoreHow to set the CSS property that the transition effect is for with JavaScript?
Use the transitionProperty property in JavaScript to set which CSS properties should have transition effects. This property controls exactly which CSS properties will animate when they change. Syntax element.style.transitionProperty = "property1, property2, ..."; element.style.transitionProperty = "all"; // All properties element.style.transitionProperty = "none"; // No transitions Example Here's a complete example showing how to set transition properties dynamically: #div1 { ...
Read MoreMake numbers in array relative to 0 – 100 in JavaScript
Let's say, we have an array that contains some numbers, our job is to write a function that takes in the array and maps all the values relative to 0 to 100. This means that the greatest number should get replaced by 100, the smallest by 0, and all others should get converted to specific numbers between 0 and 100 according to the ratio. Understanding the Formula To normalize values to a 0-100 scale, we use the formula: normalizedValue = ((value - min) / (max - min)) * 100 This formula ensures the smallest ...
Read MoreHow to set whether the text should be overridden to support multiple languages in the same document with JavaScript?
In this tutorial, we will learn how to set whether the text should be overridden to support multiple languages in the same document with JavaScript. Use the unicodeBidi property in JavaScript to set whether the text should be overridden to support multiple languages in the same document. Set it to normal, embed, or bidi-override. The bidi-override allows you to add the direction, i.e., rtl to ltr. Understanding Unicode Bidirectional Text The unicodeBidi property controls the bidirectional text algorithm for elements containing text in multiple languages, especially when mixing left-to-right (LTR) and right-to-left (RTL) scripts like Arabic or ...
Read MoreHow to handle tabs, line breaks and whitespace in a text in JavaScript?
In this tutorial, we will learn how to handle tabs, line breaks, and whitespace in text using JavaScript's CSS white-space property. JavaScript provides control over text formatting through the style.whiteSpace property. This property has several values that determine how whitespace is handled: normal - Default value; collapses multiple spaces into one, wraps text automatically pre - Preserves spaces and tabs, respects line breaks pre-wrap - Like 'pre' but also wraps long lines pre-line - Preserves line breaks but collapses spaces ...
Read MoreHow to set all the border top properties in one declaration with JavaScript?
To set all the border top properties in a single declaration, use the borderTop property. With this property, you can set the border-top-width, border-top-style, and border-top-color property in one statement. Syntax element.style.borderTop = "width style color"; Parameters The borderTop property accepts a string value containing three components: width: Border thickness (e.g., "thin", "thick", "5px") style: Border style (e.g., "solid", "dashed", "dotted") color: Border color (e.g., "red", "#000000", "rgb(255, 0, 0)") Example You can try to run the following code to learn how to work with border-top properties in JavaScript: ...
Read MoreInverse operation in JavaScript
The inverse operation on a binary string involves flipping each bit: converting all 0s to 1s and all 1s to 0s. This is a common operation in computer science and digital logic. Understanding Binary Inverse Binary inverse (also called bitwise NOT or complement) transforms each digit in a binary string to its opposite value. For example, '1101' becomes '0010'. Method 1: Using Array Methods We can split the string into individual characters, transform each one, and join them back: const num = '1101'; const n = '11010111'; const inverseBinary = (binary) => { ...
Read More