Your Search Results


    Returns a nodelist collection with a given name in the (X)HTML document.


    elements = document.getElementsByName(name) 
    • elements is an live NodeList Collection
    • name is the value of the name attribute of the element.


    <!DOCTYPE html>
    <html lang="en">
    <form name="up"><input type="text"></form>
    <div name="down"><input type="text"></div>
    var up_forms = document.getElementsByName("up");
    console.log(up_forms[0].tagName); // returns "FORM"


    The name attribute is only applicable to (X)HTML documents. The method returns NodeList Collection that contains all elements with a name attribute, such as <meta> or <object> or even if name is placed on elements which do not support a name attribute at all.

    document.getElementsByName() returns an NodeList of all the elements with a given value for the name attribute.

    The getElementsByName method works differently in different browsers. In IE & Opera, getElementsByName() method will also return elements that have an id attribute with the specified value. so you should be careful not to use the same string as both a name and an ID.