hungrykoala
hungrykoala

Reputation: 1083

how to auto populate the contents of a tinymce?

I am trying to auto populate the contents of my tinymce, this will be done in certain scenarios. I tried doing some console testing to see what jquery function will work on it.

I tried:

$("#tinymce").text("test");
$("#tinymce").html("test");
$("#tinymce").val("test");

But they all returned this error:

VM3476:1 Uncaught TypeError: $(...).val is not a function at :1:15

 <body id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('htmleditor1').onLoad.dispatch();" contenteditable="true" spellcheck="false" data-gramm_id="e2122774-06e2-55e3-4d20-705ac5c51517" data-gramm="true" data-gramm_editor="true">
<g class="gr_ gr_3 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" id="3" data-gr-id="3">sadasd</g><br>
</body>

Upvotes: 1

Views: 617

Answers (1)

Luca
Luca

Reputation: 1626

If after tinyMCE init

You must use setContent() method, so to set full content

tinyMCE.activeEditor.setContent('My test!');

or if you wanna change only selected section

tinyMCE.activeEditor.selection.setContent('<strong>Some contents</strong>');

If before tinyMCE init

You could set directly your HTML container

$('textarea').text('My text!');

Upvotes: 2

Related Questions