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 324 of 534
How to get the port number part of the href attribute of an area in JavaScript?
In this tutorial, we will discover how to get the port number of the href attribute of an area in JavaScript. An area is a tag in JavaScript. This tag is written as . This tag denotes an area inside an image map. This tag has no closing tag. So in HTML, this is an empty tag. In XHTML, this tag must be closed correctly. An image map is also another tag. This tag is written as . An image map contains an image with clickable or active areas. The area tag comes inside the map ...
Read MoreHow to set the width of the left border with JavaScript?
In this tutorial, we will learn how to set the width of the left border with JavaScript. The border property specifies the boundary of an element. It defines the border style, color, and width. To modify individual border sides, we use specific properties like borderLeftWidth for the left border. The DOM Style borderLeftWidth property allows you to set or return the width of an element's left border. Before setting the border width, ensure the element has a border style defined. Using the borderLeftWidth Property The borderLeftWidth property accepts values like "thin", "medium", "thick", or specific measurements ...
Read MoreHow to set all the background properties in one declaration with JavaScript DOM?
To set multiple background properties in JavaScript, use the background property. This shorthand property allows you to set background color, image, position, repeat, and other background-related properties in a single declaration. Syntax element.style.background = "color image repeat attachment position"; Background Property Values The background shorthand can include the following properties in any order: background-color: Sets the background color background-image: Sets the background image using url() background-repeat: Controls image repetition (repeat, no-repeat, repeat-x, repeat-y) background-position: Sets image position (left, right, center, top, bottom, or pixel values) background-attachment: Controls scrolling behavior (scroll, fixed) ...
Read MoreRecursive sum all the digits of a number JavaScript
Let's say, we are required to create a function that takes in a number and finds the sum of its digits recursively until the sum is a one-digit number. For example − findSum(12345) = 1+2+3+4+5 = 15 = 1+5 = 6 So, the output should be 6. How Recursive Digit Sum Works The process involves two levels of recursion: Extract and sum individual digits of a number Repeat the process until we get a single digit Method 1: Using Mathematical Operations ...
Read MoreHow to search the querystring part of the href attribute of an area in JavaScript?
To get the querystring from the href attribute of an area element, use the search property. This property returns the query portion of the URL, including the question mark. Syntax areaElement.search Return Value Returns a string containing the query portion of the href URL, including the leading question mark (?). Returns an empty string if no query parameters exist. Example ...
Read MoreHow to make a list of partial sums using forEach JavaScript
In JavaScript, creating a list of partial sums (also known as cumulative sums) means generating a new array where each element represents the sum of all elements up to that position in the original array. We have an array of numbers like this: const arr = [1, 1, 5, 2, -4, 6, 10]; We need to create a function that returns a new array where each element is the sum of all previous elements including itself: const output = [1, 2, 7, 9, 5, 11, 21]; Using forEach Method The ...
Read MoreHow to set a background image to be fixed with JavaScript DOM?
To set a background image to be fixed in JavaScript, use the backgroundAttachment property. This CSS property controls whether the background image scrolls with the content or remains fixed in the viewport. Understanding backgroundAttachment The backgroundAttachment property accepts three values: "scroll" - Background scrolls with content (default) "fixed" - Background stays fixed relative to viewport "local" - Background scrolls with element's content Syntax element.style.backgroundAttachment = "fixed"; Example: Fixed Background Image This example demonstrates how to set a fixed background image that won't scroll with the page content: ...
Read MoreConvert number to alphabet letter JavaScript
We are required to write a function that takes in a number between 1 and 26 (both inclusive) and returns the corresponding English alphabet for it. (capital case) If the number is out of this range return -1. For example: toAlpha(3) = C toAlpha(18) = R The ASCII Codes ASCII codes are the standard numerical representation of all the characters and numbers present on our keyboard and many more. The capital English alphabets are also mapped in the ASCII char codes, they start from 65 and go all the way up to 90, ...
Read MoreHow to get the hash part of the href attribute of an area in JavaScript?
In this tutorial, we will learn how to get the hash part of the href attribute of an area in JavaScript. The HTML element establishes an area within an image map with predetermined clickable zones. An image map allows you to correlate geometric regions of a picture with hypertext links. This element can only be used within the element. The href property gives the area's hyperlink target. The element is not a hyperlink if the href attribute is not present. Following is a method used to get the href attribute's hash part of an ...
Read MoreHow to return the background color of an element with JavaScript DOM?
In this tutorial, we will explore how to get and set the background color of an element using JavaScript DOM. The style.backgroundColor property allows us to both retrieve and modify background colors dynamically. Browser Support Chrome Browser − Version 1.0 and above. Edge Browser − Version 12 and above. Internet Explorer − Version 4.0 and above. Firefox Browser − Version 1.0 and above. Safari Browser − Version 1.0 and above. Opera Browser − Version 3.5 and above. Syntax ...
Read More