Toggling TinyMCE v4

Heres a easy way to turn on and off the TinyMCE editor for version 4.

document.getElementById('toggle-tinymce').addEventListener('click', function(e) {

  var editorID = this.dataset.editorId;
  var editor   = tinymce.EditorManager.get(editorID);

  if (editor) {
  } else {
    editor = tinymce.EditorManager.createEditor(editorID, tinyMCE.settings);

You simply then need to create a link or button as such:

<a href="#" id="toggle-tinymce" editor-id="your-editor-id">Toggle</a>

Thats it. It will remove the TinyMCE if enabled, and if not, it will re-render by re-creating the editor with settings provided by tinyMCE.settings.

Show Comments