Getting WP Tinymce's Content Getting WP Tinymce's Content wordpress wordpress

Getting WP Tinymce's Content


Try:

tinymce.activeEditor.getContent();

or

tinymce.editors.content.getContent();

Where "content" is the id of your textarea.

Similarly, if you wanted to get just the selected (highlighted) text in the TinyMCE text area you would do:

tinymce.activeEditor.selection.getContent();

The full API is here: http://tinymce.moxiecode.com/wiki.php/API3:class.tinymce.Editor

TinyMCE also offers a lot of events you can bind to, particularly in your case the keyup, keydown, and keypressed events.

Be sure to call this stuff only after TinyMCE has loaded on the page.


I remember that tiny MCE loads content dynamically from ajax, so maybe your document.getElementById('content') try to get that element too early.

I think you have 2 ways to solve this problem:

1) wait for the ajax event completition, with an event listener, and after that get the element and its text.

2) use tinyMce function to get the content of a text area. Here you may find some useful tips:http://tinymce.moxiecode.com/wiki.php/How-to_load/save_with_Ajax_in_TinyMCE


Accepted answer did work for me but for multiple editors on one page I have to access it via editor id, so below

tinymce.editors['content_id'].getContent();

Worked for me.