Search code examples
javascripthtmlmonaco-editor

Apply Monaco editor to textarea instead of div


I have the following textarea in my html-document:
<textarea id="container"></textarea>

I used the monaco.editor.create(document.getElementById('container') function to initialise the editor, but it fails, without writing some error to the console. When I change the textarea to div it works fine.

Is it possible to make it work with a textarea instead of a div?

Regards Andi


Solution

  • It is not possible to render an instance of monaco-editor to a <textarea> tag.

    Why?

    The <textarea> tag is not a container; it is a multiline, plain text edit control for the text's raw value. Additionally, the API specified by the monaco-editor developers explicitly requires an empty container.

    Additional reference