document.getElementById('frmMain').elements
can i use like this
document.getElementByName('frmMain').elements
or
document.getElementBytag('table').elements`
getElementsByName fetch all the elements with given name and returns list of elements. getElementsByTagName fetch all the elements with given Tag and returns list of elements.
getElementsByTagName() The getElementsByTagName method of Document interface returns an HTMLCollection of elements with the given tag name. The complete document is searched, including the root node.
The getElementsByName() method of the Document object returns a NodeList Collection of elements with a given name attribute in the document.
The getElementsByTagName() method returns a collection of all elements with a specified tag name. The getElementsByTagName() method returns an HTMLCollection.
name
attribute in IE, please add ID to the element if you want to use getElementById
A great alternative is
All
- it is a collection. The [0] will get the elements of the first form on the page. The "form" is a valid CSS selectorIn all of the above, the .elements
can be replaced by for example .querySelectorAll("[type=text]")
to get all text elements
getElementById returns either a reference to an element with an id matching the argument, or null if no such element exists in the document.
getElementsByName() (note the plural Elements) returns a (possibly empty) HTMLCollection of the elements with a name matching the argument. Note that IE treats the name and id attributes and properties as the same thing, so getElementsByName will return elements with matching id also.
getElementsByTagName is similar but returns a NodeList. It's all there in the relevant specifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With