document.getElementsByName

In this chapter you will learn:

  1. How to get HTML elements by name attribute in Javascript

Get elements by name

getElementsByName(nameOfNameAttribute) gets the elements by name and returns HTMLElement[].

<!DOCTYPE HTML> <!--from   jav a2s.co m-->
<html> 
    <body> 
        <p name="apple"> apple</p>
        <script> 
            var nameElems = document.getElementsByName("apple"); 
            document.writeln(nameElems.length); 
        </script> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to get all image elements in a HTML document using Javascript
Home » Javascript Tutorial » Document
Document Object
document.body
document.characterSet
document.charset
document.compatMode
document.cookie
document.defaultCharset
document.defaultView
getElementsByTagName(tagName)
document.getElementsByClassName
document.getElementsByName
document.images
document.lastModified
document.location
document.implementation
document.querySelectorAll
document.readyState
document.title
document.URL
document.writeln