I have a plugin that allows the user to dynamically add sections that need to have the tinyMCE editor in them. The jQuery clones a div and places it into a container. One of the input boxes is a textarea set up like so:

<textarea name="sectionContent_1" id="sectionContent_1"></textarea>

I need to replace the textarea with the tinyMCE editor.

I’ve looked at:

How to load wp_editor() through AJAX/jQuery
and
use wordpress wp_editor in dynamic/ajax html

Neither of these seem to work for us

I’ve tried this inside the trigger that calls to add the textarea section:

$(this).parent().find('.sectionOptions').html(ctHolder);

var textAreaID = 'sectionContent_'+sectionID;

tinyMCE.execCommand('mceRemoveEditor', true, textAreaID);
tinyMCE.execCommand('mceAddControl', false, textAreaID);

In this, I’m adding the cloned data (ctHolder) to the .sectionOptions setting the textarea’s ID, resetting the editor on the ID, then adding control to the ID… this doesn’t work but seems to be most commons suggestion.

2 Answers
2

tinymce.remove();
tinymce.init();

This works well!

Tags:

Leave a Reply

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