How to get the content of a Tinymce textarea with JavaScript

0 votes
asked Dec 29, 2010 by pooja

i have an array of content then how we get content of Tinymce textarea in javascript

6 Answers

0 votes
answered Dec 29, 2010 by ziad-el-jayyousi

lets say your mce textarea instance is:

<textarea id="editor1" ....></textarea>

then you get the content as follows:

var content =  tinyMCE.getContent('editor1');

if you mean you have multiple instances of mce editor on one page and you want to get content then try this approach:

var inst, contents = new Object();
for (inst in tinyMCE.editors) {
    if (tinyMCE.editors[inst].getContent)
        contents[inst] = tinyMCE.editors[inst].getContent();
}

the above code adds each editor content into an array

0 votes
answered Dec 3, 2011 by thariama

You may use:

tinymce.get(editorid).getContent();
0 votes
answered Dec 16, 2011 by cye

I had the same problem. I have solved using this code:

tinyMCE.get('editor1').getContent();

Source: spocke is the author

0 votes
answered Dec 18, 2012 by jqpress

I solved it with code:

// Get the HTML contents of the currently active editor
tinyMCE.activeEditor.getContent();

// Get the raw contents of the currently active editor
tinyMCE.activeEditor.getContent({format : 'raw'});

// Get content of a specific editor:
tinyMCE.get('content id').getContent()

the activeEditor is current editor,but i use tinyMCE.get('editor1').getContent() can not get the value of my editor, hope it can help you

my home page is 机器鸟

Tinymce API: http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.getContent

0 votes
answered Jan 28, 2016 by phil-mccarty

If you are more familiar with (and are using the jquery wrapper), you can also do this using this:

$('#editor1').tinymce().getContent();

Where (editor1) is your selector.

0 votes
answered Dec 13, 2016 by derenir

In my case (v4.3.12), none of the above worked, so I did a workaround:

Html code:

<div id="wrapper">
    <textarea id="editable_container" name="editable_container"></textarea>
</div>

JQuery code:

var iframe = $('#editable_container_ifr');
var editorContent = $('#tinymce[data-id="editable_container"]', iframe.contents()).html();
console.log(editorContent);

Where editable_container is my tinyMCE editor's placeholder textarea, the editable area's iframe id is generated from adding a _ifr postfix to the placeholder's id, and the content-editable container (which contains the formatted text), has an id tinymce with a data-id attribute of the placeholder's id.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...