Home > OS >  tinymce setContent works only using direct click
tinymce setContent works only using direct click

Time:07-20

the following works fine:

$('.atitle').on('click', function(){
    console.log('323');    
    tinymce.get("ed").setContent("<p>lorem ipsum</p>");  // works
});

now I need to call the above click after document.ready or window.load - but it doesn't work:

$(window).on('load', function(){
   $('.atitle').eq(0).click();
  // console is written '323' but editor is empty
});

why this happens and how to solve ?

CodePudding user response:

You cannot interact with TinyMCE until the editor itself is initialized - that is likely not the case at the point document.ready or window.load trigger.

TinyMCE has an init event that gets triggered once the editor is fully initialized and available for interaction. For example:

tinymce.init({
    selector: "textarea",
    ...
    setup: function (editor) {
        editor.on('init', function (e) {
           // Do whatever you need to do once the editor is initialized
        });
    }
});
  • Related