Html Textarea Placeholder

I have a text box that should focus on clearing the text holder and when out of focus it should return the source text or save any text that was written in focus.

EDIT:

I know how to select a region of text. $ ("Text box") text () ;.

I'm not sure how to clear the contents when you click on the text field to nothing, and then return the contents again when you are out of focus.

+4
source share
2 answers

It seems you are trying to do what you get the instructions in the text box, and then if you delete the value you get, follow the instructions again. try it

<textarea id="a">Message</textarea> var standard_message = $('#a').val(); $('#a').focus( function() { if ($(this).val() == standard_message) $(this).val(""); } ); $('#a').blur( function() { if ($(this).val() == "") $(this).val(standard_message); } ); 

You can see how it works here .

+8
source

Just add the placeholder parameter:

 <input type="text" name="name" placeholder="input placeholder" /> <textarea name="comment" placeholder="textarea placeholder"></textarea> 
+14
source

All Articles