This is what your after. It seems to work correctly on JSFiddle
HTML
<form> <textarea id='editor_instance_1'></textarea> </form> <button id='post-code-btn'>Post Code</button> <div id='post-area'></div>
Js
//create instance of an mce editor var ed = new tinymce.Editor('editor_instance_1', { //add custom formats style_formats: [ {title: 'Code', block: 'pre', styles: {'color': '#000', 'font-size': '11px'}}, {title: 'Text', block: 'p', styles: {'color': '#ff0000', 'font-size': '16px'}} ], //force the starting block to pre forced_root_block : 'pre' }, tinymce.EditorManager); //render the editor on screen ed.render(); var postButton = document.getElementById('post-code-btn'); var postArea = document.getElementById('post-area'); postButton.onclick = function(){ //get html structure from the editor instance var code = ed.getBody().innerHTML; //simulate posting of html new Request.HTML({ url: '/echo/html/', data: { html: code, delay: 0 }, type: 'post', update: 'post-area', }).send(); }
I have inserted code from several sources, including eclipse, SO, and JSFiddle.
source share