Keren Keren - 6 months ago 46
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


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(' ');