'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.
Solution 1:[1]
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);
}
Solution 2:[2]
I am using insertHtml : It will put the text at cursor position and no removal of existing text. Its like updating the content of ckeditor. this separates it from setdata()
function InsertHTML(HTML)
{
CKEDITOR.instances['editor1'].insertHtml(HTML);
}
and it works fine. ;)
Solution 3:[3]
CKEDITOR.instance['editor1'].insertElement(str);
It will be insert text in cursor position
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Heemanshu Bhalla |
Solution 2 | Heemanshu Bhalla |
Solution 3 | Mari Selvan |