button elementautofocusdisabledformformactionformenctypeformmethodformnovalidateformtargetnametypevalue
interface HTMLButtonElement : HTMLElement {
attribute boolean autofocus;
attribute boolean disabled;
readonly attribute HTMLFormElement? form;
attribute DOMString formAction;
attribute DOMString formEnctype;
attribute DOMString formMethod;
attribute boolean formNoValidate;
attribute DOMString formTarget;
attribute DOMString name;
attribute DOMString type;
attribute DOMString value;
readonly attribute boolean willValidate;
readonly attribute ValidityState validity;
readonly attribute DOMString validationMessage;
boolean checkValidity();
void setCustomValidity(DOMString error);
readonly attribute NodeList labels;
};
The button element represents
a button.
The element is a button.
The type attribute controls the
behavior of the button when it is activated. It is an enumerated attribute. The
following table lists the keywords and states for the attribute —
the keywords in the left column map to the states in the cell in
the second column on the same row as the keyword.
| Keyword | State | Brief description |
|---|---|---|
submit |
Submit Button | Submits the form. |
reset |
Reset Button | Resets the form. |
button |
Button | Does nothing. |
The missing value default is the Submit Button state.
If the type attribute is in the Submit Button state, the
element is specifically a submit
button.
The form attribute is used to explicitly associate
the button element with its form owner. The name attribute represents the element's name.
The disabled attribute is used to make the
control non-interactive and to prevent its value from being
submitted. The autofocus attribute controls focus. The
formaction, formenctype, formmethod, formnovalidate, and formtarget attributes are attributes for form
submission.
The formnovalidate attribute can be
used to make submit buttons that do not trigger the constraint
validation.
The formaction, formenctype, formmethod, formnovalidate, and formtarget must not be specified if
the element's type attribute is not in the Submit Button state.
The value attribute gives the
element's value for the purposes of form submission. The element's
value is the value of the element's
value attribute, if there is one, or the
empty string otherwise.
A button (and its value) is only included in the form submission if the button itself was used to initiate the form submission.
The following button is labeled "Show hint" and pops up a dialog box when activated:
<button type=button
onclick="alert('This 15-20 minute piece was composed by George Gershwin.')">
Show hint
</button>