How to insert custom text to JCE v. using javascript?

I have opened the page source and saw that the editor is an iframe. Text is in <body id="tinymce">.

I was trying something like:


but it doesn't work. Of course, it is executed on domReady.

  • is that element is accessible through $("body#tinymce") selector?? – subashbasnet8 Jan 26 '15 at 10:23

I have found a solution.

var id = "yourTextAreaId";
var tmce_el = tinyMCE.get(id);
if (tmce_el != undefined)
    tmce_el.execCommand('mceSetContent', false, value);
    document.getElementById(id).innerHTML = value;
    document.getElementById(id).value = value;
| improve this answer | |
  • You may accepted your own answer to mark your isssue resolved. – mickmackusa May 27 '19 at 13:32

I think the better way is to use the Joomla.editors.instances

You will be able to validate that it has the textAreaId loaded and then update with the setValue method.

if (Joomla.editors.instances.hasOwnProperty('yourTextAreaId')) {
} else {
    // do you custom script as fail-safe

I have tested this with codemirror, tinyMCE, none (when no editor is set) and it works very well.

| improve this answer | |

There is actually a custom button plugin provided by the creators of JCE...


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.