elements collection
Represents a collection of all form control elements in a form.
The form control elements are:
button, input:button, input:checkbox, input:file, input:hidden, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, select, textarea.
The elements in the collection are sorted in source code order.
The elements in the collection are sorted in source code order.
Syntax:
The base interface, through which you can add new functionalities to the elements collection, is the HTMLCollection interface.
Possible members:
Properties:
Returns an integer that specifies the number of elements in the current collection.
This property is read-only. |
Methods:
[nameOrIndex] |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
item (nameOrIndex [, subIndex]) |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
namedItem (name) |
Returns an element or a collection of elements from the current collection by name.
Parameters:
Return value:
|
||||||||||||||||||||||
tags | Returns a NodeList collection that contains all elements from the current collection with the specified tag name. | ||||||||||||||||||||||
urns | Returns a NodeList collection that contains all elements to which the specified behavior is attached. |
Example HTML code 1:
This example illustrates the use of the elements collection:
|
||||
<head> <script type="text/javascript"> function ItemTest () { var form = document.getElementById ("myForm"); var firstItem = form.elements[0]; alert ("The first control in the form:\n" + firstItem.innerHTML); var myInputs = form.elements['myInput']; alert ("The number of controls with name='myInput': " + myInputs.length); alert ("The first control with name='myInput':\n" + myInputs[0].value); } </script> </head> <body> <form id="myForm"> <span>Click on this button:</span> <button onclick="ItemTest ();">Test form items</button> <br /><br /> <input name="myInput" size="40" value="First input field" /> <br /> <input name="myInput" size="40" value="Second input field" /> </form> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments