A form-associated element can have a relationship
form element, which is called the element's
form owner. If a form-associated element is
not associated with a
form element, its form
owner is said to be null.
A form-associated element is, by default, associated
with its nearest ancestor
form element (as described
below), but may have a
form attribute specified to
This feature allows authors to work around the lack
of support for nested
If a form-associated element has a
form attribute specified, then that
attribute's value must be the ID of a
form element in
the element's owner
The rules in this section are complicated by the
fact that although conforming documents will never contain nested
form elements, it is quite possible (e.g. using a
script that performs DOM manipulation) to generate documents that
have such nested elements. They are also complicated by rules in the
HTML parser that, for historical reasons, can result in a
form-associated element being associated with a
form element that is not its ancestor.
When a form-associated element or one of its
ancestors is inserted into a
Document, then the
user agent must reset the form owner of that
form-associated element. The
HTML parser overrides this requirement when inserting
When an element is removed from a
Document resulting in a
form-associated element and its form owner
(if any) no longer being in the same host subtree, then
the user agent must reset the form owner of that
When a form-associated element has a
form attribute and an element with an
ID is inserted into or removed from the
Document, then the user agent must reset the form
owner of that form-associated element.
When the user agent is to reset the form owner of a form-associated element, it must run the following steps:
If the element's form owner is not null, and
attribute is not present, and the element's form owner
is its nearest
form element ancestor after the change
to the ancestor chain, then do nothing, and abort these
Let the element's form owner be null.
Otherwise, the element is left unassociated.
In the following non-conforming snippet:
... <form id="a"> <div id="b"></div> </form> <script> document.getElementById('b').innerHTML = '<table><tr><td><form id="c"><input id="d"></table>' + '<input id="e">'; </script> ...
This happens as follows: First, the "e" node gets associated
with "c" in the HTML parser. Then, the
innerHTML algorithm moves the nodes
from the temporary document to the "b" element. At this point, the
nodes see their ancestor chain change, and thus all the "magic"
associations done by the parser are reset to normal ancestor
This example is a non-conforming document, though, as it is a
violation of the content models to nest
Returns the element's form owner.
Returns null if there isn't one.