getElementsByName() property in HTML

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).