How can i clear the ckeditor textarea with jquery at the click of a button/link?
I have tried this : $(\"textarea.editor\").val(\'\');
and $(\"tex
The below code clears the value in the ckeditor textarea. This will works 4.4 version also.
CKEDITOR.instances['content'].setData('');
Content is the id of the particular text-area.
Try it may helpful.
function CKupdate(){
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
}
CKEDITOR.instances[instance].setData('');
}
$.ajax({
url: $('#CommunicationForm').attr("action"),
type: $('#CommunicationForm').attr("method"),
data: $('#CommunicationForm').serialize(),
success: function (e) {
if (e.error) {
alert(e.error);
} else {
//Doing Clear here
CKupdate();
}
},
error: function (jqXHR, Status, text) {
alert("error! " + text);
}
});
Call CKupdate()
function when when you want to clear CKEditor text.
In my code i had to change the text in the ckeditor programmatically but it did not work until i did a defered set. This may be helpful.
_.defer(function () {
it._controls.wysiwyg.setData(bodyText); // by the direct reference
//CKEDITOR.instances.editor1.setData(''); // or this way like in the example
});
CKEDITOR.instances.editor1.setData('');
Where editor1 is the id of your CKEDITOR field