How do I set a value in CKEditor with Javascript?

dcp3450 picture dcp3450 · Aug 31, 2010 · Viewed 111.6k times · Source

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?

Answer

efeyc picture efeyc · Dec 4, 2012

Use the CKEditor method setData():

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