Front End Technology Articles

Page 349 of 652

How to show the index of the selected option in a dropdown list with JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 12K+ Views

In JavaScript, we use the selectedIndex property to get the index of the selected option in a dropdown list. This property returns a zero-based index value that indicates which option is currently selected. Dropdown lists are an essential part of user interfaces, allowing users to select one or multiple options from a predefined list. Understanding how to retrieve the selected option's index is crucial for form handling and user interaction. Using the selectedIndex Property The selectedIndex property is part of the DOM and contains the index of the currently selected option in a dropdown list. The indexing ...

Read More

How to remove options from a dropdown list with JavaScript?

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

This tutorial teaches us how to remove options from a dropdown list using JavaScript. Usually, this is not frequent that users get the option to remove any option from the dropdown list but this is possible if the option is provided by the programmer. If the programmer wants to provide the option to remove the dropdown then in JavaScript it is possible with the help of the remove() method. Using the DOM user can select the option to remove and by providing a function it could be passed to the remove method which will remove it. Let's look into ...

Read More

How to get the value of the hreflang attribute of a link in JavaScript?

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

In this tutorial, we will learn how to get the value of the hreflang attribute of a link in JavaScript. The hreflang is an attribute of a link or anchor tag which specifies the language of the linked document or href attribute. It is used by search engines to understand the link's language and the targeted geographical location of the website. For better SEO hreflang attribute must be used. A single language or combination of language and region is used as the value of the hreflang attribute. It uses the language code ISO-639-1 and region code ISO-3166-1. ...

Read More

Is it a good practice to end switch with defaults in JavaScript?

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

In this tutorial, we will learn if it is a good practice to end switch with defaults in JavaScript. In JavaScript, we generally use the if or if-else statements if we need to check any conditions. Still, if we need to check multiple conditions for an expression, it becomes very complex and unorganized, so we use the switch statements for that situation. The switch statement compares the value of an expression to a series of case clauses, then executes statements after the first case clause that matches the value, and so on, until a break statement is met. ...

Read More

Are both addition and concatenation same in JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 2K+ Views

In JavaScript, addition and concatenation are fundamentally different operations that can produce similar results depending on the data types involved. The + operator performs both operations contextually, while the concat() method is specifically for concatenation. The + operator behaves differently based on operand types: when at least one operand is a string, it performs concatenation; when both operands are numbers, it performs arithmetic addition. The concat() method, however, is only available for strings and arrays. String Operations For strings, both + operator and concat() method produce identical results. Using Addition (+) ...

Read More

How to get the value of the rel attribute of a link in JavaScript?

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

In this tutorial, we will learn how to get the value of the rel attribute of a link in JavaScript. The rel attribute expresses the relationship between the current document or website and the linked document or website. The search engine uses this attribute to get more information about the link, so it is important for the SEO of the website. The rel attribute can have different values like alternate, author, external, nofollow, etc.; each value means different information about the link. For example, 'alternate' means the link represents an alternate version of the current document. Using ...

Read More

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 966 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
Showing 3481–3490 of 6,519 articles
« Prev 1 347 348 349 350 351 652 Next »
Advertisements