I’m struggling to add dynamically a tinymce textarea.

I added a custom meta box which contains a button that should add a tinymce.
As I’m on post/page, I guess I don’t need to include any scripts because all is included due to the main tinymce editor.

I followed this help post but it doesn’t work for me
Dynamically textarea with TinyMce editor

My Script

function textarea_to_tinymce(id){
    if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
        tinyMCE.execCommand('mceAddControl', false, id);
    }
}

jQuery('.button').click(function() {    
    jQuery("#text-container").append('<textarea class="content" id="test" name="test"></textarea>');
    textarea_to_tinymce("test");
    return false;
});

I’m currently have no idea what I’m doing wrong. The textarea just don’t transform to a tinymce. In fact the tinyMCE.execCommand(‘mceAddControl’, false, id); just does not have any impact and I don’t know why. Does anyone have some help for me?
Thanks

1 Answer
1

This works for me:

tinyMCE.execCommand("mceAddEditor", false, id);
tinyMCE.execCommand('mceAddControl', false, id);

Leave a Reply

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