Keren Keren - 1 year ago 101
jQuery Question

How to add back placeholder after value is emptied?

After clearing textarea's value, the placeholder goes missing. All I need to do is, to add back that placeholder into the textarea.


<textarea data-reply placeholder="Add your reply" autocomplete="off" name="message" ></textarea>

clear the textarea value

$('[data-reply]').val(' ');

adding placeholder (doesn't work)

1) $('[data-reply]').attr("placeholder", "New placeholder text");

2) $("textarea[placeholder]").attr("placeholder", "New placeholder text");

referred here: Changing the "placeholder" attribute of HTML5 input elements dynamically using Javascript

Answer Source

You don't have to do anything. Browser will show the placeholder after the value is cleared.

The value you put into textarea is not clearing it. It's a single space character.

$('[data-reply]').val(' ');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download