Javascript Articles

Page 410 of 534

How to find the inner height and inner width of a browser window in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 688 Views

In this article we are going to learn how to find the inner height and inner width of a browser window using JavaScript. JavaScript defines window object methods and properties. The properties include inner height and inner width, which helps us to calculate the height and width of a window's content area excluding scrollbars, toolbars, and other browser UI elements. There are two main approaches to calculate the inner height and inner width of a window: Using innerHeight and innerWidth properties − The window.innerHeight and window.innerWidth properties return the viewport dimensions including padding ...

Read More

What is the importance of '/g' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 659 Views

The /g flag in JavaScript regular expressions stands for "global" and is essential for finding all matches in a string rather than stopping after the first match. Without this flag, regex methods will only find the first occurrence of a pattern. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created in two ways: Literal notation: Uses forward slashes with optional flags after the second slash (e.g., /pattern/g). This is preferred when the pattern remains constant. Constructor function: Uses new RegExp("pattern", "flags"). This is useful when the pattern ...

Read More

What is the importance of '/i' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 536 Views

The /i flag in JavaScript is a regular expression modifier that enables case-insensitive pattern matching. By default, regular expressions are case-sensitive, meaning they distinguish between uppercase and lowercase letters. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created using two methods: Literal notation: Uses slashes to enclose the pattern (/pattern/flags). Best for static patterns that won't change during execution. Constructor method: Uses the RegExp constructor (new RegExp("pattern", "flags")). Ideal when the pattern needs to be dynamic or constructed at runtime. ...

Read More

What is importance of startsWith() method in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 197 Views

To check whether a string starts with a particular character or substring, the indexOf() method was traditionally used. However, ES6 introduced the more intuitive and readable startsWith() method, which is specifically designed for this purpose and offers better performance and clarity. Traditional Approach: Using indexOf() The indexOf() method returns the first index where a substring is found. To check if a string starts with specific characters, we compare the result with 0: var text = 'Tutorialspoint'; document.write(text.indexOf('T') === 0); true ...

Read More

What is the use of test() method in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

The test() method is a regular expression method that searches a string for a pattern and returns true or false, depending on whether the pattern is found. It is case sensitive and provides a simple way to check if a string matches a regular expression pattern. Syntax regexPattern.test(string) Parameters string - The string to be tested against the regular expression pattern Return Value Returns true if the pattern is found in the string, false otherwise. Example 1: Pattern Found (Case Match) In this example, ...

Read More

How to know the browser language and browser platform in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 773 Views

In this article we are going to discuss how to know the browser language and browser platform with the help of examples in JavaScript To know the various properties of the browser, JavaScript provides the Navigator object. The Navigator object has several properties, which include - connection, credentials, cookies, geolocation, language, platform, etc. We are concerned with Navigator.language and Navigator.platform to know the language and platform of the browser. Let us discuss about them in detail. Navigator.language The read-only Navigator.language property returns a string that represents the browser UI language. It returns a string that contains the ...

Read More

How to find the href and target attributes in a link in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 7K+ Views

In JavaScript, you can access and manipulate the href and target attributes of anchor elements using DOM methods. These attributes control where links point and how they open. Finding href and target Attributes You can retrieve these attributes using getAttribute() or directly access them as properties of the anchor element. Finding href and target attributes TutorialsPoint let link = document.getElementById('myLink'); ...

Read More

How to get a particular anchor in a document in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 2K+ Views

In this article we will learn how to get a particular anchor in a document in JavaScript. JavaScript provides multiple ways to access anchor elements ( tags) in a document. Anchor elements follow an array-like structure, allowing you to select specific anchors by index or use DOM methods to retrieve them. There are two primary methods to get a particular anchor element: using document.anchors collection or document.getElementsByTagName("a") method. Syntax The syntax to get a particular anchor tag is shown below: // Method 1: Using document.anchors collection document.anchors[index].innerHTML // Method 2: Using getElementsByTagName document.getElementsByTagName("a")[index].innerHTML ...

Read More

How to find the number of links in a document in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 1K+ Views

The document.links property in JavaScript provides access to all links in a document. It returns a collection of and elements that contain an href attribute. Syntax To get the total number of links in a document, use: document.links.length The document.links property returns an HTMLCollection that behaves like an array, allowing you to access individual links by index and get the total count using the length property. Example 1: Basic Link Count Here's a simple example to count the links in a document: JavaScript ...

Read More

How to display the domain of the server that loaded a document in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 567 Views

In this following article we are going to learn how to display the domain of the server that loaded a document in JavaScript. To display the domain of the server, we use domain property of the document interface, which returns the domain part of the current document. The domain property will return NULL if the document was created in memory. Attempting to set the domain property of the document interface results in SecurityError. To understand better, let's look into the syntax and usage of domain property with suitable examples in JavaScript. Using document.domain Property We can ...

Read More
Showing 4091–4100 of 5,340 articles
« Prev 1 408 409 410 411 412 534 Next »
Advertisements