Button type Property
Example
Return the type of a button:
var x = document.getElementById("myBtn").type;
The result of x will be:
button
Try it yourself »
Definition and Usage
The type property sets or returns the type of a button.
Tip: Always specify the type attribute for the button. The default type for Internet Explorer is "button", while in other browsers (and in the W3C specification) it is "submit".
Browser Support
The type property is supported in all major browsers.
Syntax
Return the type property:
buttonObject.type
Set the type property:
buttonObject.type="submit|button|reset"
Property Values
Value | Description |
---|---|
submit | The button is a submit button (this is default for all browsers, except Internet Explorer) |
button | The button is a clickable button (this is default for Internet Explorer) |
reset | The button is a reset button (clears form data) |
Technical Details
Return Value: | A String, representing the button type |
---|
More Examples
Example
Change the type of a button to "submit":
document.getElementById("myBtn").type = "submit";
Try it yourself »
Example
Change the type of a button to "reset":
document.getElementById("myBtn").type = "reset";
Try it yourself »
Related Pages
HTML reference: HTML <button> type attribute
Button Object