Take the 2-minute tour ×

I would like to remove the initial space in a textarea. When there is no text given to a textarea and you get the textarea.value, you get a single space " " instead of the empty string like a normal input textbox. Also when there is text (i.e. test) it returns " test". Is it possible to prevent this extra space? I would prefer to work with the prototype of Textarea because I am using a general procedure to get the values of both input textboxes and textarea's.

For the moment I wrote something like this:

Textarea.prototype.value = function() {
        var val = this.value;
        if (val[0] == "0") val.splice(0,1);
        return val;

But it doesn't solve the problem, I still get the extra space.

share|improve this question
What does your markup look like? –  Sergio Tulentsev Apr 21 '12 at 19:02
To tell the same thing as Sergio in other words: that space exists because your markup put it there. –  Jon Apr 21 '12 at 19:04
It's most likely because you have the opening and closing <textarea> tags on different lines in your code. –  Rory McCrossan Apr 21 '12 at 19:05

3 Answers 3

up vote 6 down vote accepted

Your HTML should be like this:

---------^ no space, tab or new line there 
share|improve this answer

Simply make sure that there is no space between opening and closing tags eg follwing are wrong:

<textarea> </textarea>




share|improve this answer

" \b" would result in "". So you could concatinate the string with \b to eliminate the last character of a string

share|improve this answer

Your Answer


