I try to set id4
in the following code:
<div id="id1"> <div id="id2"> <div id="id3"> <textarea id="id4"></textarea> </div> </div> </div>
By using this code:
document.getElementById('id4').value = "...";
And this:
document.getElementById('id3').getElementsByTagName('textarea')[0].value = "...";
But nothing works.
The textarea
is replaced by CodeMirror editor. How do I set value to it?
Thanks a lot for the help!
The easiest way to set up CodeMirror is via <script> tag from a CDN. You can also bundle the CodeMirror npm module, but for the sake of example let's just use a CDN. Just make sure you include both the JavaScript and CSS files, otherwise your editor won't look right.
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) .
CodeMirror is a code editor component for the web. It can be used in websites to implement a text input field with support for many editing features, and has a rich programming interface to allow further extension.
The way to do this has changed slightly since the release of 3.0. It's now something like this:
var textArea = document.getElementById('myScript'); var editor = CodeMirror.fromTextArea(textArea); editor.getDoc().setValue('var msg = "Hi";');
I like examples. Try this:
CodeMirror.fromTextArea(document.getElementById(id), { lineNumbers: true }).setValue("your code here");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With