Skip to content
Advertisement

How to insert text dynamically in CKEDITOR

I use plugin CKEDITOR for word editor in my web. Inside the editor I have a table which have two columns . I want to achieve that in the first column if the user input number it will add to (50) and the result automatically appear in the second column. That is very easy using Jquery but it does not work. Tried codes:

function insertIntoCkeditor(str){
  CKEDITOR.instances['editor1'].insertText(str);
}

but this code insert automatically above the text area of the editor.

Advertisement

Answer

Use

setData()

It will remove the existing data in the ckeditor and and it will replace it with ‘str’ variable content.

function insertIntoCkeditor(str){
    CKEDITOR.instances['editor1'].setData(str);
}
Advertisement