
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Button name Property
The HTML DOM Button name property is associated with name attribute of the <button> element. The name property is used to set or return the value of the name attribute of the button. The name attribute is used in forms to select an element using JavaScript.
Syntax
Following is the syntax for −
Setting the name property −
buttonObject.name = name
Here, the name property value is used to denote the name of the button.
Example
Let us see an example of the button name property −
<!DOCTYPE html> <html> <body> <button id="button1" name="btn1">BUTTON</button> <p>Click the button below and change the above button name.</p> <button onclick="change()">CHANGE</button> <p id="Sample"></p> <script> function change() { document.getElementById("button1").name="SECOND BUTTON"; var x=document.getElementById("button1").name; document.getElementById("Sample").innerHTML="The new button name is "+x; } </script> </body> </html>
Output
This will produce the following output −
On clicking CHANGE −
In the above example −
We have first created a button with id “button1” and name “btn1”
<button id="Button1">BUTTON</button>
We have then created the CHANGE button that executes the method change() on click .
<button onclick="change()">CHANGE</button>
The change() function gets the button element with id “button1” and changes its name attribute value to “SECOND BUTTON”. The name value of the button is then assigned to variable x and finally displayed in the paragraph with id “Sample”
function change() { document.getElementById("button1").name="SECOND BUTTON"; var x=document.getElementById("button1").name; document.getElementById("Sample").innerHTML="The new button name is "+x; }
- Related Articles
- HTML DOM Input Button name Property
- HTML DOM Button autofocus Property
- HTML DOM Button disabled Property
- HTML DOM Button type Property
- HTML DOM Button value Property
- HTML DOM Input Button type Property
- HTML DOM Input Button value Property
- HTML DOM Input Button disabled Property
- HTML DOM Input Button form Property
- HTML DOM name Property
- HTML DOM Object name Property
- HTML DOM Textarea name Property
- HTML DOM Form name Property
- HTML DOM Fieldset name property
- HTML DOM Select name Property
