Reputation: 107
How I can change my textarea content on click to be empty?
Here is the code:
<textarea name="adventage" style="width:400px; border-radius: 3px; border-left: 4px solid #6C3" id="adventage" cols="45" rows="5">Share with everyone what are the advantages of this vehicle. </textarea>
The idea is on click to this area, it will be empty for typing new text.
Upvotes: 0
Views: 257
Reputation: 3713
You can get that functionality using the placeholder
attribute
<textarea placeholder='Share with everyone what are the advantages of this vehicle.'></textarea>
It is the standard and easiest way (no javascript involved, you can see it working in stackoverflow's search textbox in the top of this page!).
It will not work in old browsers though (IE9 and older), if you need it to work in those browsers you can check this question
Upvotes: 4
Reputation: 121998
try like this.
For the first time place holder works.But if you have sometext already inside that (in case of editing
) do some scripting
.
$(document).ready(function(){
$('#adventage').click(function(){
$(this).val('');
})
});
Upvotes: 0
Reputation: 1
$(document).ready(function(){
$("textarea[name='adventage']").click(function({
$(this).innerHTML("");
}))
})
This should work!
Upvotes: 0
Reputation: 5699
HTML
<textarea class="my_textarea" name="adventage" id="adventage" cols="45" rows="5">Share with everyone what are the advantages of this vehicle. </textarea>
JQUERY
$("#adventage").click(function() {
$(this).empty();
});
CSS
#adventage { width:400px; border-radius: 3px; border-left: 4px solid #6C3; }
Upvotes: 0