## HTML DOM Button name Property
## Definition and Usage
The name property sets or returns the value of the name attribute of a button.
The name attribute specifies the name for a button.
The name attribute is used to reference form-data after the form has been submitted, or to reference the element in a JavaScript.
## Browser Support
| Property | | | | | |
| --------- | :-: | :-: | :-: | :-: | :-: |
| name | Yes | Yes | Yes | Yes | Yes |
## Syntax
Return the name property:
*buttonObject*.name
Set the name property:
*buttonObject*.name=*name*
## Property Values
| Parameter | Description |
| --------- | ------------ |
| name | A string specifying the name of the button. The name can be used to reference the button in JavaScript. |
## Technical Details
| Return Value: | A String, representing the name of the button |
| -------------- | ------------------------------------------- |
| DOM Version: | Core Level 1. More examples |
## Example
The following example shows how to get the name of a button:
```html
First name:
Last name:
Click the "Try it" button to get the name of the Submit button:
function myFunction() {
var x = document.getElementsByTagName("BUTTON");
document.getElementById("demo").innerHTML = x.name;
}
```
## Try it Yourself Β»
## Example 2
The following example shows how to set the name of a button:
```html
Click the "Try it" button to set the name of the button to "newButtonName":
function myFunction() {
var x = document.getElementById("myBtn");
x.name = "newButtonName";
document.getElementById("demo").innerHTML = x.name;
}
```
## Related Pages
HTML tutorial: (
HTML reference: [HTML