Why am I getting the placeholder value for my textarea if I have no text in the element? Shouldn't I just be getting a empty string, and not the placeholder value?
As you can see from the example, it doesn't alert the placeholder-text.
alert($('textarea').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea name="text" placeholder="this is a test"></textarea>
How are you displaying the placeholder text? Some sources recommend something along the lines of this for placeholder text in a textarea:
<textarea>
PLACEHOLDER CONTENT
</textarea>
If this is the method you are using, the interior content will be treated as the value, not the placeholder. The proper route would be something along these lines:
<textarea placeholder="PLACEHOLDER CONTENT"></textarea>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.