Button type attribute
Definition and usage
type
Property settings or return the button type.
Tip:Always specify the button's type attribute:
- The default type of Internet Explorer is "button"
- It is "submit" in other browsers (and in the W3C specification)
Example
Example 1
Return the button type:
var x = document.getElementById("myBtn").type;
Example 2
Change the button type to "submit":
document.getElementById("myBtn").type = "submit";
Example 3
Change the button type to "reset":
document.getElementById("myBtn").type = "reset";
Syntax
Return the type attribute:
buttonObject.type
Set the type attribute:
buttonObject.type = "submit|button|reset"
Attribute value
Value | Description |
---|---|
submit | The button is a submit button (default setting in all browsers except IE). |
button | The button is a clickable button (default in IE). |
reset | The button is a reset button (clears form data). |
Technical Details
Return Value: | A string value representing the button type. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
Related Pages
HTML Reference Manual:HTML <button> type Attribute