<button>

The <button> element inherits the HTMLButtonElement interface. It has the following instance attributes.

(1) HTMLButtonElement.accessKey

The HTMLButtonElement.accessKey property returns a string representing the corresponding key on the keyboard. The button can be focused by Alt + this key. This attribute can be read and written.

(2) HTMLButtonElement.autofocus

The HTMLButtonElement.autofocus property is a Boolean value that indicates whether the button will automatically gain focus during page loading. This attribute can be read and written.

(3) HTMLButtonElement.disabled

The HTMLButtonElement.disabled property is a boolean value, indicating whether the button is forbidden to click. This attribute can be read and written.

(4) HTMLButtonElement.form

The HTMLButtonElement.form property is a form element and returns the form where the button is located. This attribute is read-only. If the button does not belong to any form, this property returns null.

(5) HTMLButtonElement.formAction

HTMLButtonElement.formAction returns a string representing the URL of the form submission. This attribute is readable and writable. Once the value is set, clicking the button will submit to the URL specified by this attribute instead of the URL specified by the <form> element.

(6) HTMLButtonElement.formEnctype

The HTMLButtonElement.formEnctype attribute is a string that represents the encoding type of the data submitted to the server. This attribute is readable and writable. Once the value is set, clicking the button will follow the encoding specified by the attribute instead of the encoding specified by the <form> element.

This attribute can take the following values.

-application/x-www-form-urlencoded (default value) -multipart/form-data (encoding method of uploaded file) -text/plain

(7) HTMLButtonElement.formMethod

The HTMLButtonElement.formMethod property is a string that represents the HTTP method for the browser to submit the form. This attribute is readable and writable. Once the value is set, the HTTP method specified by this attribute will be used after clicking, instead of the encoding method specified by the <form> element.

(8) HTMLButtonElement.formNoValidate

The HTMLButtonElement.formNoValidate property is a boolean value that indicates whether to skip the form verification step when the button is clicked to submit the form. This attribute is readable and writable. Once set, it will override the novalidate attribute of the <form> element.

(9) HTMLButtonElement.formTarget

The HTMLButtonElement.formTarget property is a string that specifies which window displays the content returned by the server after the form is submitted. This attribute is readable and writable. Once set, it will override the target attribute of the <form> element.

(10) HTMLButtonElement.labels

HTMLButtonElement.labels returns an instance of NodeList, representing those <label> elements that are bound to the button. This attribute is read-only.

/* HTML code is as follows
  <label id="label1" for="test">Label 1</label>
  <button id="test">Button</button>
  <label id="label2" for="test">Label 2</label>
*/

const button = document.getElementById("test");

for (var i = 0; i < button.labels.length; i++) {
  console.log(button.labels[i].textContent);
}
// "Label 1"
// "Label 2"

In the above code, the two <label> elements are bound to the <button> element. button.labels returns these two <label> elements.

(11) HTMLButtonElement.name

The HTMLButtonElement.name property is a string representing the name property of the button element. If the name attribute is not set, an empty string is returned. This attribute can be read and written.

(12) HTMLButtonElement.tabIndex

HTMLButtonElement.tabIndex is an integer representing the tab order of button elements. This attribute can be read and written.

(13) HTMLButtonElement.type

The HTMLButtonElement.type property is a string that represents the behavior of the button. This attribute is readable and writable, and may take the following values.

-submit: The default value, which means submitting the form. -reset: Reset the form. -button: There is no default behavior.

(14) HTMLButtonElement.validationMessage

The HTMLButtonElement.validationMessage property is a string that indicates the prompt message displayed when the verification fails. This attribute is read-only.

(15) HTMLButtonElement.validity

The HTMLButtonElement.validity property returns the validation state (ValidityState) of the button. This attribute is read-only.

(16) HTMLButtonElement.value

The HTMLButtonElement.value property returns the value bound to the button. This attribute can be read and written.

(17) HTMLButtonElement.willValidate

The HTMLButtonElement.willValidate property is a boolean value that indicates whether the button will be validated when the form is submitted. The default is false. This attribute is read-only.