HTML DOM Input Button value Property


The HTML DOM value property returns and modify the content of the value attribute of input button.

Syntax

Following is the syntax −

1. Returning value

object.value

2. Modifying value

object.value=”text”

Example

Let us see an example of value property

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM value Property</title>
<style>
   body{
      text-align:center
   }
   .btn{
      display:block;
      margin:1rem auto;
      background-color:#db133a;
      color:#fff;
      border:1px solid #db133a;
      padding:0.5rem;
      border-radius:50px;
      width:80%;
   }
   .show-value{
      font-weight:bold;
      font-size:1.4rem;
      color:#ffc107;
</style>
</head>
<body>
<h1>value Property Example</h1>
<input type="submit" onclick="setValue()" class="btn" value="Click me to change my
text">
<div class="show-value"></div>
<script>
   function setValue() {
      var btn= document.querySelector(".btn");
      document.querySelector(".show-value").innerHTML ="Previous Value = " + btn.value;
      document.querySelector(".btn").value = "Congrats! you have successfully changed my value";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Click me to change my text” button to change red button value.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements