HTML | DOM Button Value Property - GeeksforGeeks
Có thể bạn quan tâm
The Button value Property is used to set or return the value of the value attribute of a button element. The value attribute for <button> element in HTML is used to specify the initial value of the button element.
Syntax:
- It is used to return the value property.
- It is used to set the value property.
Property Values:
- text: It specify the initial value of the Button.
Return Value: It returns a string value which represent the initial value of the button.
Example 1: This example illustrates how to return the value Property.
HTML
<!DOCTYPE html> <html> <head> <title> HTML DOM button value Property </title> </head> <body style="text-align:center"> <h1>GeeksforGeeks</h1> <h2> HTML DOM button value Property </h2> <button id="btn" value="GeeksforGeeks" onclick="myGeeks()"> Click Here! </button> <p id="result"></p> <script> function myGeeks() { let x = document.getElementById("btn").value; document.getElementById("result").innerHTML = x; } </script> </body> </html> |
Output:
Example 2: This example illustrates how to set the value Property.
HTML
<!DOCTYPE html> <html> <head> <title> HTML DOM button value Property </title> </head> <body style="text-align:center"> <h1>GeeksforGeeks</h1> <h2> HTML DOM button value Property </h2> <button id="btn" value="User" onclick="myGeeks()"> Click Here </button> <p id="result"></p> <script> function myGeeks() { let x = document.getElementById("btn").value = "GeeksForGeeks" document.getElementById("result").innerHTML = "The value changed from User to " + x; } </script> </body> </html> |
Output:
Supported Browsers:
- Google Chrome
- Edge 12 and above
- Internet Explorer
- Firefox
- Opera
- Safari
M
ManasChhabra2 Follow Improve Previous Article HTML | DOM Input Button form Property Next ArticleTừ khóa » Html Button Properties
-
Attributes
-
CSS Buttons - W3Schools
-
The Button Element - HTML: HyperText Markup Language | MDN
-
HTML Button Tag - Usage, Attributes, Examples | W3Docs
-
HTML Button Tag - Javatpoint
-
Learn Attributes Of HTML Button Tag - EduCBA
-
HTML Button Type – How To Add Buttons To Your Website
-
Creating A Button With The HTML Button Element: Here's How »
-
Button Type In HTML: Here's Why You Should Always Declare It »
-
HTML
-
HTML Button Tag - Types, Effects And Attributes - DataFlair
-
Learn HTML Buttons In 5 Minutes 🛎️ - YouTube
-
Ion-button: Design And Style Buttons With Custom CSS Properties
-
HTML Button Style Attribute - Dofactory