Document.getElementsByName() (Method)

An accessor method for retrieving objects from within the DOM hierarchy specifically according to their NAME value.


DOM level - 1
JavaScript - 1.5
JScript - 5.0
Internet Explorer - 5.0
Netscape - 6.0
Opera - 5.0
Property/method value type:NodeList object
JavaScript syntax:-myDocument.getElementsByName(aName)
Argument list:aNameThe name of the element to be retrieved

Sometimes, it can be inconvenient to walk the document hierarchy to locate an object by its NAME. One alternative is to search the all[] collection but this is a linear search that takes place serially through the document object collection from beginning to end. It can take quite a while to locate the object.

There may also be some conflict in locating objects. The ID and NAME attributes are different and yet often the two namespaces are combined and searched together.

This method is a faster way of locating object specifically by its NAME value and ignoring its ID value. It searches the only unmerged namespace for the NAME value.