2

If I have a HTML document containing this snippet:

    <form name="my_awesome_form" action="http:///handler.blah" method="post">
        <input type="text" name="test_input"/>
        <input type="submit" value="submitter" />
    </form>

Then I open the javascript console of firefox's developer tools, and type the word document.

> document.addEventListener
           __proto__             <-- list of completions
           activeElement
           my_awesome_form

the developer tools generates a list of completions i.e. properties on the document object.
I can see that the name attribute name="my_awesome_form" I gave to my form appears in this list and that is is a reference to the DOM element of my form.
My question is what is responsible for this and where can I find the documentation for this?

I have looked at MDN document API documentation but it seems that the browser has automatically added this post-processing of the page, so its obviously not hardcoded into the DOM API interface that the document object inherits from.
I've also looked here https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268
but can't find an explanation there either.

the_velour_fog
  • 2,094
  • 4
  • 17
  • 29
  • You might find these helpful: https://www.tjvantoll.com/2012/07/19/dom-element-references-as-global-variables/ and http://stackoverflow.com/questions/32957798/reference-a-dom-element-as-a-property-of-the-window-object – SimianAngel Jul 25 '16 at 03:24
  • @SimianAngel thanks for the links. Those links are related to the properties defined on the window object. My question is about the document object. Unless there is some relationship going on between the two that I am missing, I think they are similar --but different things – the_velour_fog Jul 25 '16 at 03:33
  • @the_velour_fog See http://stackoverflow.com/questions/8946320/whats-the-point-of-html-forms-name-attribute – guest271314 Jul 25 '16 at 07:01
  • @guest271314 thanks, the answer you linked to contained this link to [w3c html5 spec](https://www.w3.org/TR/html5/forms.html#attr-form-name). From the spec *The name attribute represents the form's name within the forms collection.* I tested it and yes my form can be accessed with `document.forms.my_awesome_form` so I guess the `document.my_awesome_form` is just an alias to `document.forms.my_awesome_form` – the_velour_fog Jul 25 '16 at 07:20

0 Answers0