HTML DOM Textarea name Property

HTMLDOMWeb DevelopmentFront End Technology

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

Syntax

Following is the syntax −

1. Returning name

object.name

2. Adding name

object.name = “text”

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

Example

<!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;
   }
   .show {
      font-size: 1.5rem;
      margin: 1rem 0;
   }
</style>
<body>
<h1>DOM Textarea name Property Demo</h1>
<textarea rows="5" cols='20' name="I'm name attribute of textarea element">
Hi! I'm a textarea element with some dummy text.
</textarea>
<button onclick="set()" class="btn">Show Name Attribute Value</button>
<div class='show'></div>
<script>
   function set() {
      document.querySelector('.show').innerHTML = document.querySelector("textarea").name;
   }
</script>
</body>
</html>

Output

Click on “Show Name Attribute Value” button to display the value of name attribute of the textarea element.

raja
Published on 20-Sep-2019 14:45:31
Advertisements