Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a value of CodeMirror editor by javascript?

How to set a value of CodeMirror editor by javascript command? I just need to set a text to it. But how?.. Thanks a lot for the help!

like image 380
Dmitry Avatar asked Dec 04 '11 22:12

Dmitry


People also ask

How do I use CodeMirror?

Once you import CodeMirror via <script> tag, you get a CodeMirror global that you can use to create a new CodeMirror instance. Just point it at a <div> and CodeMirror does the rest. CodeMirror(document. querySelector('#my-div'), { lineNumbers: true, tabSize: 2, value: 'console.

How do I reset CodeMirror editor?

If you don't want to kill the CodeMirror instance, just change the entire document holding the text, data on markers etc. This can be done by calling cm. swapDoc(doc: CodeMirror. Doc) .

How do I create a CodeMirror instance?

// create an instance var editor = CodeMirror. fromTextArea('code'); // store it $('#code'). data('CodeMirrorInstance', editor); // get it var myInstance = $('code'). data('CodeMirrorInstance'); // from here on the API functions are available to 'myInstance' again.


1 Answers

It is explained in the manual, section Programming API:

setValue(string): Set the editor content.

like image 128
Felix Kling Avatar answered Oct 12 '22 10:10

Felix Kling