How do I set a value in CKEditor with Javascript?

I am wondering how I can set a value in CKEditor using Javascript?

I have tried the following, but neither of them work...

document.[form name].[textarea name].value=data;
$('#textareaID').val(data);

However, both these work without the editor applied. Is there a way I can do this with the editor?


Use the CKEditor method setData():

CKEDITOR.instances[**fieldname**].setData(**your data**)

The insertHtml() and insertText() methods will insert data into the editor window, adding to whatever is there already.

However, to replace the entire editor content, use setData().


Use insertHtml() or insertText() method.


Try This

CKEDITOR.instances['textareaId'].setData(value);