JavaScript DHTML/Node Operation/getElementsByName
"getElementsByName()" Example
<source lang="html4strict">
<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>
This is a div element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
This is a p element
<input type="button"
value="Get the number of elements that have the same name" onClick="function1();">
</body> </html>
</source>
Get tags by name
<source lang="html4strict">
<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();">
- option 1
- option 2
Paragraph
<form name="elem6">
<input type="text" name="elem7" />
</form> </body> </html>
</source>