How to set value in CKEditor using Javascript?

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

I tried the following, but none of them work ...

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

However, both of these functions work without using an editor. Is there any way to do this with the editor?

+46
javascript ckeditor
Aug 31 '10 at 14:32
source share
8 answers

Use the CKEditor setData() method:

 CKEDITOR.instances[**fieldname**].setData(**your data**) 
+65
Dec 04
source share

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

However, to replace all editor content, use setData() .

+28
Jun 23 '12 at 18:26
source share

Use the insertHtml () or insertText () method.

+10
Aug 31 2018-10-10
source share

I used the code below and it works fine by describing →

 CKEDITOR.instances.mail_msg.insertText(obj["template"]); 

CKEDITOR > CKEDITOR → Your editor Name, mail_msg → Id of your text field (to which u binds ckeditor), obj["template"] → is the value that u wants to bind

+6
Jun 15 2018-12-12T00:
source share

try it

 CKEDITOR.instances['textareaId'].setData(value); 
+3
Jun 16 '16 at 6:30
source share

Sets the editor data. Data must be provided in raw format (HTML). CKEDITOR.instances.editor1.setData ("Put your data"); link to this page

+2
Jan 19 '15 at 9:09
source share

Take care to infer newline characters from any line you pass into setData(). Otherwise, an exception is thrown.

Also note that even if you do this and then getData(), this data again using getData(), CKEditor puts the rows back.

+1
May 6 '13 at 19:06
source share
 <textarea id="editor1" name="editor1">This is sample text</textarea> <div id="trackingDiv" ></div> <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script> 

Try this..

Update:

To set the data:

Create an instance of First ::

 var editor = CKEDITOR.instances['editor1']; 

Then

 editor.setData('your data'); 

or

 editor.insertHtml('your html data'); 

or

 editor.insertText('your text data'); 

And extracting data from your editor ::

 editor.getData(); 

If in CKEditor to change separate data pair HTML.

 var html = $(editor.editable.$); $('#id_of_para',html).html('your html data'); 

Here are the possible ways that I know in CKEditor

+1
Nov 18 '16 at 10:21
source share



All Articles