Javascript Articles

Page 317 of 534

How to work with document.embeds in JavaScript?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 227 Views

The document.embeds property in JavaScript provides access to all elements in an HTML document. It returns an HTMLCollection containing all embed elements, which is useful for managing embedded content like videos, audio files, or plugins. Syntax document.embeds document.embeds.length document.embeds[index] document.embeds.namedItem(name) Basic Example Here's how to count and access embed elements in a document: Document Embeds Example ...

Read More

Query-string encoding of a Javascript Object

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 254 Views

The query string is made up of query parameters and used to send data to the server. This part of the URL is optional and needs to be constructed by the developer. This can be done using a native method called encodeURIComponent(). The encodeURIComponent() function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character. Using Object.keys() and map() Using ES6 features, objects can be query string encoded by combining Object.keys(), map(), and join() methods: let ...

Read More

How to convert Binary to Decimal in JavaScript?

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

In this tutorial, we will learn to convert binary to decimal in JavaScript. A binary number is a string of '0' and '1' digits, representing numbers in base 2 format used in digital electronics. Here are two different methods to convert binary numbers to decimal: Using the parseInt() Method The parseInt() method can extract numbers from strings and accepts a base parameter, making it perfect for binary conversion. Syntax let binary = "0101"; let decimal = parseInt(binary, 2); Parameters binary − The binary number as a string base − The ...

Read More

Increment a date in javascript without using any libraries?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 223 Views

To increment a date in JavaScript without external libraries, use the setDate() method. This approach automatically handles month and year rollovers. Using setDate() Method The setDate() method accepts day values beyond the current month's range. JavaScript automatically adjusts the month and year when necessary. let date = new Date('2024-01-31'); // January 31st date.setDate(date.getDate() + 1); // Add 1 day console.log(date.toDateString()); Thu Feb 01 2024 Creating a Reusable Function You can extend the Date prototype or create a standalone function to add days: Date.prototype.addDays = function(days) { ...

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.images in JavaScript?

Arushi
Arushi
Updated on 15-Mar-2026 563 Views

The document.images property in JavaScript provides access to all elements in a document. It returns an HTMLCollection containing all image elements, allowing you to count, access, and manipulate images programmatically. Syntax document.images document.images.length document.images[index] document.images.namedItem(name) Properties and Methods The document.images collection provides: length - Returns the number of images in the document [index] - Access image by numeric index (0-based) namedItem() - Access image by name or id attribute Example: Counting Images ...

Read More

How to create an object property from a variable value in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 9K+ Views

JavaScript has two notations for creating object properties: dot notation and bracket notation. To create an object property from a variable value, you need to use bracket notation or ES6 computed property names. Method 1: Using Bracket Notation (Dynamic Assignment) You can assign properties to existing objects using bracket notation with variable names: const obj = {a: 'foo'}; const prop = 'bar'; // Set the property using the variable name prop obj[prop] = 'baz'; console.log(obj); { a: 'foo', bar: 'baz' } Method 2: Using ES6 Computed Property Names ES6 ...

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
Showing 3161–3170 of 5,340 articles
« Prev 1 315 316 317 318 319 534 Next »
Advertisements