Reputation: 731
I want to change to the content with id in CKEditor. I will create a table in CKEditor like a template. I researched in help doc (http://docs.ckeditor.com/) but I couldn't find how to do.
I want to add the content I write in the text box when I clicked the button.
Source: http://jsfiddle.net/mstfcck/m2g4mj83/
CKEDITOR.replace('RichTextEditor');
CKEDITOR.instances.RichTextEditor.setData("<div id='message'>This is a message.</div>");
Upvotes: 0
Views: 315
Reputation: 60
you should use the getById() and setText() like in the following code:
CKEDITOR.replace('RichTextEditor');
CKEDITOR.instances.RichTextEditor.setData("<div id='message'>This is a message.</div>");
$("#change").on("click", function(){
var element = CKEDITOR.instances.RichTextEditor.document.getById( 'message' );
element.setText($("#messageBox").val());
});
Working fiddle: http://jsfiddle.net/m2g4mj83/5/
Here is the documentation for both:
http://docs.ckeditor.com/#!/api/CKEDITOR.dom.document-method-getById
http://docs.ckeditor.com/#!/api/CKEDITOR.dom.element-method-setText
Upvotes: 2