How to get tinymce content in jquery?

I am trying to get tinymce data but getting tinyMCE undefined. Here is my code:

function savePost( ){ 

    console.log(  jQuery('#wp_tinymce_editor').tinyMCE().getContent() );
}

check

+4
source share
1 answer

The TinyMCE object / library is the one that is responsible for your editor, so you should use this object to get the content.

You can use activeEditorfor this, or if (for some reason) you have the source element that the editor created in the jQuery object, you can use this jQuery object to get the idoriginal element and use this to get the contents of TinyMCE (using the TinyMCE editor )

jQuery -

- jQuery ( , ), id , _ifr . , , , tinymce html, dom, getContent.

:

$('#btn1').click(function() {
    console.log(tinyMCE.activeEditor.getContent());
});
$('#btn2').click(function() {
    console.log(tinyMCE.editors[$('#ta').attr('id')].getContent());
});
$('#btn3').click(function() {
    alert('You should really NOT use this option');
    console.log($('#ta_ifr')[0].contentDocument.body.innerHTML);
});

: https://jsfiddle.net/8tdf3q22/

+8

Source: https://habr.com/ru/post/1651571/


All Articles