getElementsByName() property in HTML

By Mahak Gupta Mar 01, 2012
getElementsByName() property access all elements which we will specify in it.
getElementsByName()  property access all elements which we will specify in it.

<script type="text/javascript">
function getNumberOfElements()
var x=document.getElementsByName("btn");

<input name="btn" type="button" value="First" />
<input name="btn" type="button" value="Second" />
<input name="btn1" type="button" value="Third" />
<input name="btn" type="button" value="Forth" />
<input name="btn" type="button" value="Fifth" />
<input name="btn" type="button" value="Sixth" /><br /><br /> 
<input type="button" onclick="getNumberOfElements()" value="Click here to find the number of elements that have the same name" />


In this example the alert box shows the number of button element (btn).

Mahak Gupta
Mahak Gupta

My name is Mahak Gupta. I am a C# Corner MVP.


Latest Blogs