0% found this document useful (0 votes)
13 views2 pages

JavaScript - Document - getElementsByName Method

Uploaded by

Swapnil Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

JavaScript - Document - getElementsByName Method

Uploaded by

Swapnil Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/8/23, 9:42 AM JavaScript - document.

getElementsByName() method - javatpoint

Javascript - document.getElementsByName() method


The document.getElementsByName() method returns all the element of specified name.

The syntax of the getElementsByName() method is given below:

document.getElementsByName("name")

Here, name is required.

Example of document.getElementsByName() method

In this example, we going to count total number of genders. Here, we are using
getElementsByName() method to get all the genders.

<script type="text/javascript">
function totalelements()
{
var allgenders=document.getElementsByName("gender");
alert("Total Genders:"+allgenders.length);
}
</script>

https://www.javatpoint.com/document-getElementsByName()-method 2/6
8/8/23, 9:42 AM JavaScript - document.getElementsByName() method - javatpoint

<form>
Male:<input type="radio" name="gender" value="male">
Female:<input type="radio" name="gender" value="female">

<input type="button" onclick="totalelements()" value="Total Genders">


</form>

Output of the above example

Male: Female: Total Genders

← Prev Next →

Youtube For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to [email protected]

Help Others, Please Share

https://www.javatpoint.com/document-getElementsByName()-method 3/6

You might also like