JavaScript DHTML/Node Operation/getElementsByName
"getElementsByName()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var m = document.getElementsByName("myE");
alert(m.length);
}
</script>
<a name="myE"
href="http://www.wbex.ru"
onclick="return(false);">This is a link
</a>
<div name="myE">This is a div element</div>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<p name="myE" style="cursor:hand">This is a p element</p>
<input type="button"
value="Get the number of elements that have the same name"
onClick="function1();">
</body>
</html>
Get tags by name
<html>
<head>
<title></title>
<script type="text/javascript">
function findName() {
var typeStr = "";
var nmStr = "elem1";
var nmList = document.getElementsByName(nmStr);
typeStr += nmList[0].tagName + " ";
alert(typeStr);
}
</script>
</head>
<body onload="findName();">
<div name="elem1">
<ul name="elem2">
<li>option 1</li>
<li name="elem3">option 2</li>
</ul>
</div>
<p name="elem5">Paragraph</p>
<form name="elem6">
<input type="text" name="elem7" />
</form>
</body>
</html>