Categories
JavaScript Answers

How to fix CKEditor instance already exists error with JavaScript?

Spread the love

Sometimes, we want to fix CKEditor instance already exists error with JavaScript.

In this article, we’ll look at how to fix CKEditor instance already exists error with JavaScript.

How to fix CKEditor instance already exists error with JavaScript?

To fix CKEditor instance already exists error with JavaScript, we destroy the existing instance if it already exists.

For instance, we write

const editor = CKEDITOR.instances[name];
if (editor) {
  editor.destroy(true);
}
CKEDITOR.replace(name);

to get the editor instance with CKEDITOR.instances[name].

If editor is defined, then we call editor.destroy with true to destroy the instance.

Then we call CKEDITOR.replace with name to create a new CKEditor instance with name.

Conclusion

To fix CKEditor instance already exists error with JavaScript, we destroy the existing instance if it already exists.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *