G
G
gromyko212020-11-15 12:01:53
CKEditor
gromyko21, 2020-11-15 12:01:53

How to insert a tag in a textarea?

There is a text area

<textarea name="content" id="id_content"></textarea>

The code that replaces it with ckeditor
document.addEventListener("DOMContentLoaded", function (event) {
        var editor = CKEDITOR.replace('id_content');
    });

Replaced correctly, no problems.
I need to insert a tag into this area, as I understand it, this is done using insertHtml:
CKEDITOR.instances.id_content.insertHtml('<p>This is a new paragraph.</p>');

And this code throws an error
Uncaught TypeError: CKEDITOR.instances.id_content is undefined

How can I insert an img tag there?
Note:
The code below produces undefined So I get object. With this method (when replacing), he adds everything as it should.
console.log(CKEDITOR.instances['id_content'])
console.log(CKEDITOR.instances)
document.addEventListener("DOMContentLoaded", function (event) {
        var editor = CKEDITOR.replace( 'id_content', {
       on: {
          instanceReady: function() {
              this.insertHtml( '<h1>someText</h1>' );
          }
       }
} );
    });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question