Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinyMCE setContent - dynamically (jQuery) added textarea

I have some fields listed on my page, each has a button that creates a textarea that is to be converted to tinyMCE, and the content shall be updated with a string that is from an ajax request. Like this:

$("table td.bio-td").delegate(".btn", "click", function() {
     ...         
     var id = this.id;
     $('#cont').html('<textarea id="mceeditor_'+id'">xyz</textarea>');
     tinymce.EditorManager.execCommand('mceAddControl',true, 'mceeditor_'+id);
     tinymce.activeEditor.setContent(ajax_str);
     ...
});

The code works properly except for one thing: the setContent() line. I get an error in the javascript console, that the activeEditor is null. Somehow tinyMCE cannot find the editor in the DOM? Then how did it convert to tinymce object before?

like image 794
waszil Avatar asked Mar 10 '26 07:03

waszil


2 Answers

Try doing:


tinymce.get('your_textarea_id').focus();
tinymce.activeEditor.setContent(ajax_str);

Hope it helps

like image 114
Sudhir Bastakoti Avatar answered Mar 11 '26 20:03

Sudhir Bastakoti


Easiest way is

tinymce.get('mceeditor_'+id).setContent(ajax_str);
like image 44
Thariama Avatar answered Mar 11 '26 21:03

Thariama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!