I'm trying to dynamically update the HTML5 placeholder
attribute of a text field using jQuery.
$("textarea").attr("placeholder", "New placeholder text");
From Firebug, I can observe that the placeholder
attribute is indeed changing. But in the rendered textarea
element, it stays the same. Any suggestions?
A placeholder is meant to describe the generic pattern of expected input, not some specific value. If you have a useful default value e.g. from previous input, make it the default by putting it into the value attribute (property) and omit the placeholder attribute as not needed.
<input type="text" placeholder="A red placeholder text..">
To change the placeholder text of an input element with JavaScript, we can set the placeholder property of an element. Then we can set the placeholder attribute value for each input element by writing: document. getElementsByName('Email')[0].
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.
try this :
$('#inputTextID').attr("placeholder","placeholder text");
I think you have to do that :
$("textarea").val(''); $("textarea").attr("placeholder", "New placeholder text");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With