Introduction
This blog explains most important and repeated using methods, events of CKEditor. If you didn’t know CKEditor, please read Introduction to CKEditor.
Invoke or Initialize CKeditor
- <textarea name="htmlcontent" id="myckeditor" > hi.! I am Ckeditor </textarea>
- CKEDITOR.replace('myckeditor');
Replace <textarea> with CKEditor instance. For textareas, the initial value in the editor will be the textarea value (hi.! I am Ckeditor). If I use DOM elements (<div>), their ‘innerHTML’ will be used instead. It is recommended to use <textarea> and <div> elements only.
Is available of CKEditor
Check CKEditor is attached with our elements.
- var isCkeditor = typeof CKEDITOR.instances[myckeditor] != 'undefined';
isCkEditor returns true/false, which is based on our element(myckeditor) and is attached with CKEditor.
Destroy or Remove CKEditor
Remove CKEditor instances from our element. The elment (<textarea> or <div> ) will be recovered from CKEditor. Before going to destroy, it must update the element, using ‘updateElement()’ method.
- if(typeof CKEDITOR.instances[myckeditor] != 'undefined') {
- setTimeout(function () {
- CKEDITOR.instances[myckeditor].updateElement();
- CKEDITOR.instances[myckeditor].destroy();
- }, );
- }
Events and type
CKEditor have lots of events and methods. Events are triggered when particular dom element is clicked or focus or something happened. We will catch these events, using CKEditor instance ready method.
Here, mention few events and its types.
Paste event
An event is triggered when we paste some content in to CKEditor or paste from dialog (paste as Word, plain text).
- CKEDITOR.on('instanceReady', function(ev) {
- ev.editor.on('paste', function(evt) {
- if (evt.data.type == 'html') {
- // when paste as plain text or direct paste in ckeditor body.
- }
- if (evt.data.type == 'text') {
- // when paste as text or paste from word.
- }
- });
- });
Focus and Blur Editor Content
An event is triggered when editor content is focus or blur.
- CKEDITOR.on('instanceReady', function(ev) {
- ev.editor.on('focus', function(evt) {
- console.log(“Editor focused”)
- });
- ev.editor.on('blur', function(evt) {
- console.log(“Editor blur”)
- });
- });

Join the conversation! Your thoughts help the community grow.