jQuery - remove user input text from textarea

帅比萌擦擦* 提交于 2019-11-30 06:37:37

You're looking for .val():

$("#commentField").val('');

Example: http://jsfiddle.net/andrewwhitaker/q6eLV/

Since textarea is a input field it has a value property so you have to use val() method. Try this

$("#commentField").val('');

In jQuery it's actually $("#commentField").val(" ");

You can remove text from the textarea like this:

$("#commentField").html("");

EDIT: ok, this does not work, but I'd be really interested as to why, and I understand the down-vote. I always thought that the text between the textarea tags was innerHTML and html() is supposed to replace just that. Wouldn't it make sense to have textarea like input? or is it just because textareas contain long amounts of text that would look tacky between quotation marks?.

Using regular javascript with innerHTML it works for me in FF6. demo here

1) <textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
2) CKEDITOR.replace('editor1');
3) initiated = true;
to write your text in you text area
1)$("#editor1").val("your input value");
to clean your text area
1) $("#editor1").reset();
tank you for reading this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!