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
Front End Technology Articles
Page 348 of 652
How to find the number of anchors with JavaScript?
In this tutorial, we will learn how to count the number of anchor elements ( tags) in an HTML document using JavaScript. The document.anchors property provides a way to access all anchors with a name attribute in the document. Note: The document.anchors property is deprecated and only counts anchors with a name attribute. For modern development, use document.querySelectorAll('a') instead. Using document.anchors (Deprecated) The document.anchors property returns an HTMLCollection containing all anchor elements that have a name attribute. You can use the length property to get the count. Syntax let anchors = document.anchors; let numberOfAnchors ...
Read MoreHow to show name/value pairs of cookies in a document with JavaScript?
We use the cookie property of the document object to show the name/value pairs of cookies in a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. A server serves requests when a connection is set up and forgets everything about the user as soon as the connection is closed. This posed a nasty problem of bad user experience to the community. A cookie resolves this problem by storing small ...
Read MoreHow to convert Number to Boolean in JavaScript?
This tutorial will teach us to convert a number to a Boolean in JavaScript. The variable of Boolean data type can contain only two values, true and false. When we convert the variables of any other data type to Boolean, it returns true for all non-falsy values and false for all falsy values. Let's understand the falsy values. JavaScript contains 6+ falsy values, and some of them are as below. Null 0 NaN False Undefined ' ' (empty string) ...
Read MoreHow to show the full URL of a document with JavaScript?
We use the URL property of the document object to show the full URL of a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It contains all the information about the condition of the browser as well as the web page. URL stands for Uniform Resource Locator. It contains the address of a resource on the internet. A typical URL looks something like this: http://www.example.com/index.html The Document Object Model of JavaScript acts as a layer of abstraction on the HTML page, creating ...
Read MoreHow to convert Number to String in JavaScript?
This tutorial will teach us to convert the number to string in JavaScript. Changing the type of variable is called the type conversion of a variable. While coding, the programmer needs to deal with the different data types and might need to convert the variable's data type. Every programming language has different methods to convert one variable from one data type to another data type, and JavaScript also has some methods, which are explained below. Using the toString() Method Concatenating with an empty String Using ...
Read MoreHow to use JavaScript to replace the content of a document with JavaScript?
In this tutorial, we will learn how to use JavaScript to replace the entire content of an HTML document. JavaScript provides three document methods that work together to achieve this: open(), write(), and close(). The Three Methods document.open() − Opens a new document stream for writing. It takes two optional parameters: the MIME type (typically "text/html") and "replace" to replace the current document's history entry. document.write() − Writes content to the document stream. ...
Read MoreHow to find the id of the form a button belongs to in JavaScript?
In this tutorial, we will learn how we can find the id of the form element to which a button belongs using JavaScript. In HTML, we can use button tag in two ways with form tag, where it can be used to perform some activity in the form when it is clicked, as listed below − Button is inside the FORM tag Button is outside the FORM tag No matter where the button is located, whether it is inside or outside, we can find the ID of the form tag ...
Read MoreHow to find the text visible on the button with JavaScript?
In this tutorial, we will discuss different approaches to find the text visible on the button with JavaScript. The text on a button shows what will happen if you click the button. To extract the text on the button, JavaScript provides us with the following two properties. Using the innerHTML Property Using the innerText Property Let us discuss both of the above properties in detail. Using the innerHTML Property The innerHTML property not only allows us to get the text inside any tag but also allows us to set the text ...
Read MoreHow to select multiple options in a dropdown list with JavaScript?
In JavaScript, you can enable multiple selection in a dropdown list by setting the multiple property to true. This allows users to select multiple options by holding Ctrl (Windows) or Cmd (Mac) while clicking. Syntax function enableMultipleSelection() { document.getElementById("selectId").multiple = true; } How It Works The multiple property controls whether a select element allows multiple selections. When set to true, users can select multiple options using keyboard modifiers: Ctrl + Click (Windows/Linux) to select multiple individual options Cmd + Click (Mac) to select multiple individual options Shift + Click ...
Read MoreHow to get the number of options in the dropdown list with JavaScript?
This tutorial shows different ways to get the number of options in a dropdown list using JavaScript. When working with HTML forms, you may need to count dropdown options for validation or dynamic functionality. A dropdown list is created using the tag with multiple elements. JavaScript provides several methods to count these options programmatically. Using options.length Property The most straightforward method is accessing the options.length property of a select element. First, get the select element by its ID, then use the options.length property. Syntax var selectElement = document.getElementById("dropdown"); var optionCount = selectElement.options.length; ...
Read More