The placeholder
property sets or gets the placeholder attribute of a textarea.
The placeholder attribute sets a short hint text that describes the expected value of a textarea.
placeholder |
Yes | 10.0 | Yes | Yes | Yes |
Return the placeholder property.
var v = textareaObject.placeholder
Set the placeholder property.
textareaObject.placeholder=text
Value | Description |
---|---|
text | Set a short hint text that explains the expected value of the textarea |
A String type value representing a short hint text that explains the expected value of the textarea.
The following code shows how to change the placeholder text of a textarea.
<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea" placeholder="Your address..">
</textarea>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w w . ja v a 2 s . co m-->
document.getElementById("myTextarea").placeholder = "new message";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the placeholder text of a textarea.
<!DOCTYPE html>
<html>
<body>
Address:<br>
<textarea id="myTextarea" placeholder="Your address..">
</textarea>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w ww. j a va 2s.co m-->
var x = document.getElementById("myTextarea").placeholder;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: