Web Development Articles

Page 363 of 801

How to perform numeric sort in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 12K+ Views

In JavaScript, the sort() method can be used to sort numeric arrays, but it requires a compare function for proper numeric ordering. Without it, numbers are sorted as strings, leading to unexpected results. The Problem with Default sort() When using sort() without a compare function, JavaScript converts numbers to strings and compares them lexicographically (alphabetically). This causes "10" to come before "2" because "1" comes before "2" in string comparison. let my_array = [61, 34, 54, 2, 12, 67, 89, ...

Read More

How to work with document.anchors in JavaScript?

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

In this tutorial, let us discuss how to work with the document's anchor in JavaScript. The document.anchors property is a legacy feature that returns a collection of all anchor elements with a name attribute. While modern web development no longer recommends this property, some browsers still support it for compatibility reasons. The anchor tag represents hyperlinks and navigation points within a document. For document.anchors to include an anchor element, it must have a name attribute — elements with only href attributes are not included. Syntax let anchors = document.anchors; Properties length ...

Read More

How to work with document.body in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 10K+ Views

In this tutorial, we will learn how to work with document.body in JavaScript. The document.body property provides access to the HTML element, which contains all visible content of a web page including headings, paragraphs, images, hyperlinks, tables, and lists. In an HTML document, there can only be one element. In this tutorial, we will work with the document.body in JavaScript for: Change the background color of the body Add a new element at the end of the body Change the Background Color Using document.body ...

Read More

How to work with document.head in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In this tutorial, let us discuss how to work with the document's head in JavaScript. The document.head property is a DOM Level 3 read-only feature that returns the element of the current document. This property provides access to metadata elements like title, meta tags, stylesheets, and scripts. The head tag contains document metadata including title, keywords, description, and stylesheets. Every HTML document should have a head section, though the opening and closing tags are optional in HTML. Syntax let headElement = document.head; Return Value The document.head property returns the HTML ...

Read More

How to work with document.forms in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 4K+ Views

In this tutorial, let us discuss how to work with document.forms in JavaScript. The document.forms property returns a collection of all form elements in the document. This property is read-only and provides access to form elements, their properties, and methods. It's part of the DOM Level 1 specification. Syntax var forms = document.forms; let formLen = forms.length; let formId = forms[0].id || forms.item(0).id; let formItemId = forms[0].elements[0].id; let formItemVal = forms[0].elements[0].value; let formData = forms.namedItem("testForm").innerHTML; The above syntax returns the collection of forms, total number of forms, form ID, form element ID, form element ...

Read More

How to return the protocol (http or https) of the web page with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will look at how to find which protocol is being used by a web page. A web page mostly uses http or https protocol. A protocol is a type of standard which is used to specify how the data is transferred or transmitted between different sets of computers. HTTP − HTTP is a protocol for retrieving resources such as HTML pages. It is one of the most essential and the backbone for all types of data exchange that happens over the internet. HTTP is a client-server protocol which means that all the requests are done ...

Read More

How to work with document.links in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In JavaScript, the document.links property provides access to all anchor () and area () elements that have an href attribute. This DOM property returns a live HTMLCollection of clickable links in the document. Syntax let links = document.links; Properties The document.links collection provides one main property: length − Returns the number of links in the collection. Working with document.links Properties The example below demonstrates how to access link properties. Note that only elements with href attributes are included in the collection. Working ...

Read More

How to return a number of bits used to display one color on a window screen in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 309 Views

In this tutorial, we will explore how we can find out the number of bits that are used to display a single color on the screen of our device using JavaScript. JavaScript has many inbuilt functions that allow us to get information about the various properties of the display screen. We'll be using one such function to accomplish the task mentioned above. As discussed in the previous section, we want to find out the exact number of bits that are used to display a particular color on the user's display screen by using JavaScript. Before we can access the ...

Read More

How to change the value of an attribute in javascript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 23K+ Views

In JavaScript, changing attribute values dynamically allows you to create interactive web pages. Whether you need to modify styles, swap images, or update element properties, JavaScript provides several methods to manipulate HTML attributes. To change an attribute value, you first need to access the HTML element using methods like getElementById(), then modify the attribute directly or use methods like setAttribute(). Syntax Here are the main approaches to change attribute values: // Direct property access element.attribute = new_value; // Using setAttribute method element.setAttribute("attribute", "value"); Parameters attribute − The name of the ...

Read More

How to set the amount by which the border image area extends beyond the border box with JavaScript?

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

In this tutorial, we will learn how to set the amount by which the border image area extends beyond the border box in JavaScript. To set the amount by which the border image is extended, you need to set the border outside edges. To do this we can apply the borderImageOutset style property provided in JavaScript. After creating a border image area for the HTML element, we might have to increase the area. By knowing a method to increase the border image area more than the border box, we can make the change without writing lengthy code. Using ...

Read More
Showing 3621–3630 of 8,010 articles
« Prev 1 361 362 363 364 365 801 Next »
Advertisements