There is such code:

var script = editor.document.createElement('script'); script.setAttribute( 'type', 'text/javascript'); script.setHtml('$(document).ready(function() { console.log("Скрипт вставлен"); });'); editor.insertElement(script); 

In the document it inserts, but for some reason in the "p" element:

 <p> <script type="text/javascript"> $(document).ready(function() { console.log("Скрипт вставлен"); }); </script> </p> 

And it gives an error:

 ReferenceError: $ is not defined ...re=[],b=this.getDocument().$.documentElement,c=this.$;c&&c!=b;){var d=c.parentN... 

    1 answer 1

    By default, CKeditor creates a new p tag every time you press enter .
    This can be changed using the following setting added to the configuration file:

     // Вариант А config.enterMode = CKEDITOR.ENTER_P; // вставит <p></p> // Вариант Б config.enterMode = CKEDITOR.ENTER_DIV; // вставит <div></div> // Вариант В config.enterMode = CKEDITOR.ENTER_BR; // вставит <br/> 

    Perhaps adding this configuration to the configuration file will help:

     config.fillEmptyBlocks = false; 

    Full list of settings for CKeditor

    Plus, try using the editor.insertHTML method instead of editor.insertElement .

    Or, if this does not help, try building the content manually using the following methods: editor.getData and editor.setData .

    Full list of CKEDITOR.editor methods