I want to have a textarea that starts with "I am " but it is non removable, like I want it to always be there not a placeholder as well as no one can remove it which gets hidden when text is starting to be written. How would I do this for a textarea.
Code From Fiddle
HTML
<input type="text" class="prefix" value="prefix_" >
Javascript
$('input.prefix').keyup(function(){
var prefix = 'prefix_';
if(!(this.value.match('^prefix_'))){
this.value = prefix;
}
});
$('input.prefix').blur(function(){
var prefix = 'prefix_';
if(!(this.value.match('^prefix_'))){
this.value = prefix;
}
});
The code in your fiddel is close. Instead of replacing the content with
prefix
replace it withprefix
and the valueExample: http://jsfiddle.net/vBBpS/1/
On a side note, you should move the common code to a function.