JavaScript getElementsByName() Method Tutorial

In this section, we will learn what the document getElementsByName() method is and how to use it in JavaScript.

What is document getElementsByName() Method in JavaScript?

The JavaScript document getElementsByName() method is a way of accessing elements in an HTML document using the value set for the name attribute.

For example, if there are multiple elements in an HTML document that have the name attribute with the value “light”, then calling this method and passing this value as its argument, will return a collection object that contains a reference to each element with this value set for its name attribute.

document getElementsByName() Method Syntax:

document.getElementsByName(name);

document getElementsByName() Method Parameters

The method takes one argument and that is a value set for the name attribute in an HTML document.

document getElementsByName() Method Return Value

The return value of this method is a reference to a collection object that contains the entire elements on a page that has the same value set for their name attribute.

Example: using document getElementsByName() Method in JavaScript

See the Pen using document getElementsByName() Method in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies