Button name attribute

Definition and usage

name Attribute sets or returns the button's The value of the attribute.

The value of the Specify the button's name, used to reference submitted form data, or to reference elements in JavaScript.

Instance

Example 1

Return the value of the button's name attribute:

var x = document.getElementById("myBtn").name;

Try It Yourself

Example 2

Change the value of the button's name attribute:

document.getElementById("myBtn").name = "newButtonName";

Try It Yourself

Syntax

Return name attribute:

buttonObject.name

Set name attribute:

buttonObject.name = name

Attribute Value

Value Description
name Specifies the name of the button.

Technical Details

Return Value: A string value representing the name of the button.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <button> name Attribute