Javascript Articles

Page 339 of 534

Set whether the flexible items should wrap or not with JavaScript?

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

In this tutorial, we will learn how to control whether flexible items should wrap or not using JavaScript's flexWrap property. The flexWrap property determines if flex items should wrap to new lines when there isn't enough space in the container. This is essential for creating responsive layouts. Using the Style flexWrap Property The flexWrap property defines whether flex items wrap within their container. The container must have display: flex for this property to work. The default value is nowrap. Syntax object.style.flexWrap = "nowrap|wrap|wrap-reverse|initial|inherit" Values nowrap − Items will not wrap ...

Read More

How to set the page-break behavior after an element with JavaScript?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 921 Views

Use the pageBreakAfter property in JavaScript to control page-break behavior after an element. This property is essential for formatting printed documents and print previews. Note: Changes are only visible when printing the page or viewing print preview (Ctrl+P). Syntax element.style.pageBreakAfter = "value"; Property Values Value Description auto Default - automatic page breaks always Forces page break after element avoid Avoids page break after element left Forces page break to left page right Forces page break to right page ...

Read More

Sort the numbers so that the even numbers are ahead JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

We have an array of numbers that contains some positive and negative even and odd numbers. We need to sort the array in ascending order but with a special requirement: all even numbers should appear before any odd number, and both groups should be sorted internally in ascending order. For example, if we have an array like [-2, 3, 6, -12, 9, 2, -4, -11, -8], the result should be [-12, -8, -4, -2, 2, 6, -11, 3, 9]. How It Works The solution uses a custom comparator function that: Checks if numbers are even ...

Read More

How to set the brightness and contrast of an image with JavaScript?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 4K+ Views

JavaScript provides the CSS filter property to adjust image brightness and contrast dynamically. You access these filters through the style.filter property on image elements. Syntax element.style.filter = "brightness(value) contrast(value)"; Parameters Filter Default Value Range Effect brightness() 100% 0% to 200%+ 0% = black, 100% = normal, 200% = very bright contrast() 100% 0% to 200%+ 0% = gray, 100% = normal, 200% = high contrast Example: Interactive Brightness and Contrast Click below to change the brightness ...

Read More

Find and return array positions of multiple values JavaScript

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

We have to write a function, say findPositions() that takes in two arrays as argument. And it should return an array of the indices of all the elements of the second array present in the first array. For example − If the first array is ['john', 'doe', 'chris', 'snow', 'john', 'chris'], And the second array is ['john', 'chris'] Then the output should be − [0, 2, 4, 5] Therefore, let's write the code for this function. We will use a forEach() loop here. Example const values = ['michael', ...

Read More

How to set the page-break behavior inside an element with JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 3K+ Views

Use the pageBreakInside property in JavaScript to control page-break behavior inside an element when printing. This property determines whether a page break should occur within an element's content. Note − The changes are only visible when printing or viewing the print preview. Syntax element.style.pageBreakInside = "value"; Property Values Value Description auto Allow page breaks inside the element (default) avoid Avoid page breaks inside the element if possible inherit Inherit from parent element Example: Setting Page Break Behavior Here's how to control ...

Read More

Construct string via recursion JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 382 Views

We are required to write a recursive function, say pickString that takes in a string that contains a combination of alphabets and numbers and returns a new string consisting of only alphabets. For example, If the string is 'dis122344as65t34er', The output will be: 'disaster' Therefore, let's write the code for this recursive function − Syntax const pickString = (str, len = 0, res = '') => { if(len < str.length){ const char = parseInt(str[len], 10) ? '' : str[len]; ...

Read More

How to set the minimum number of lines for an element that must be left at the bottom of a page when a page break occurs inside an element with JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 167 Views

The orphans property in CSS controls the minimum number of lines that must remain at the bottom of a page when a page break occurs inside an element. In JavaScript, you can manipulate this property through the style object. Syntax To get the orphans property: var result = element.style.orphans; To set the orphans property: element.style.orphans = 'number|initial|inherit'; Property Values number − Specify the minimum number of visible lines that must remain at the bottom initial − Set property to its default value ...

Read More

How to multiply odd index values JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 430 Views

We are required to write a function that takes in an array of Number literals as one and the only argument. The numbers that are situated at even index should be returned as it is. But the numbers situated at the odd index should be returned multiplied by their corresponding indices. For example: If the input is: [5, 10, 15, 20, 25, 30, 50, 100] Then the function should return: [5, 10, 15, 60, 25, 150, 50, 700] Understanding the Logic Let's break down what happens at each ...

Read More

How to set the left position of a positioned element with JavaScript?

Rishi Raj
Rishi Raj
Updated on 15-Mar-2026 1K+ Views

To set the left position of a positioned element in JavaScript, use the style.left property. This property works on elements that have a CSS position value of absolute, relative, or fixed. Syntax element.style.left = "value"; The value can be specified in pixels (px), percentages (%), or other CSS units like em, rem, etc. Example Here's how to change the left position of a button when clicked: #myButton { ...

Read More
Showing 3381–3390 of 5,340 articles
« Prev 1 337 338 339 340 341 534 Next »
Advertisements