If you can use jQuery, and I highly recommend you do this, you just do
$('#myTextArea').val('');
Otherwise, it is browser dependent. Assuming you have
var myTextArea = document.getElementById('myTextArea');
In most browsers you
myTextArea.innerHTML = '';
But in Firefox you do
myTextArea.innerText = '';
Finding out which browser the user is using remains as an exercise for the reader. If you are not using jQuery, of course;)
Edit : I take it back. It appears that support for .innerHTML on textarea has improved. I tested in Chrome, Firefox and Internet Explorer, they all cleared the text box correctly.
Change 2 . And I just checked if you use .val ('') in jQuery, it just sets the .value property for textarea's. So the value should be good.
Aistina Oct 29 '09 at 9:17 2009-10-29 09:17
source share