HTML DOM Textarea defaultValue Property


The HTML DOM Textarea defaultValue property returns and modify the default value of a text area element in an HTML document.

Syntax

Following is the syntax −

1. Returning defaultValue

object.defaultValue

2. Adding defaultValue

object.defaultValue = “text”

Let us see an example of HTML DOM Textarea defaultValue Property:

Example

Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      background: lightseagreen;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
<body>
<h1>DOM Textarea defaultValue Property Demo</h1>
<textarea rows="5" cols='20'>Hi! I'm a textarea element with some dummy text.</textarea>
<button onclick="set()" class="btn">Change Defualt Value</button>
<script>
   function set() {
      document.querySelector("textarea").defaultValue = "Hi! I'm default value of textarea element.";
   }
</script>
</body>
</html>

Output

Click on “Change Default Value” button to change the default value of the textarea element.

Updated on: 16-Feb-2021

67 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements