HTML DOM Button value Property

The HTML DOM Button value property is associated with value attribute of the

Syntax

Following is the syntax for ?

Setting the value property ?

buttonObject.value = text

Here, the text property value is the initial value that is given to the button.

Example

Let us see an example of the button value property ?




Click on the below button to change the above button value

Output

This will produce the following output ?

On clicking CHANGE ?

We have first created a button with value "FirstButton" with id "button1".

We have then created a button CHANGE which will execute the changeFunc() on click.

The changeFunc() method will get the first button element using its id "Button1" and change its value from "FirstButton" to "SecondButton". The newly changed button value is then assigned to the variable x and is displayed inside the paragraph with id "Sample".

function changeFunc() {
   document.getElementById("Button1").value = "SecondButton";
   var x=document.getElementById("Button1").value;
   document.getElementById("Sample").innerHTML="The button value is now "+x;
}
Updated on: 2026-03-11T22:50:45+05:30

293 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements