Stefan
Stefan

Reputation: 14863

Can't clear textarea once Text has changed in Firefox and Chrome

Simple use case: Textarea and Button, when the button is clicked, the text in the Textarea changes.

Sample: JS

$('button').click(function(){
    $('#t1').text('test');
});

HTML:

<textarea id="t1" cols="10" rows="5"></textarea><button>Clear</button>

Fiddler example

However when I change the button and then click the button the Text doesn't change in Chrome and Firefeox (in IE10 it works as). (Tested in the latest versions of Chrome and Firefox)

When I debugg it and, check the text of the textarea, it displayes the correct valeu.

Is this a browser bug, jQuery bug or am I missing something?

Upvotes: 4

Views: 2368

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337570

A textarea element has a value, so use val('') to set it, like this:

$('button').click(function(){
    $('#t1').val('test');
});

Example fiddle

Upvotes: 4

Related Questions