Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset Codemirror editor?

Tags:

codemirror

I would like to reset all the contents of the Codemirror editor. Ideally, this should clear the textarea, remove all marks and clear the history.

What's the best way to achieve this?

like image 902
sthomps Avatar asked May 04 '13 19:05

sthomps


People also ask

How to CLEAR CodeMirror JavaScript?

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 set up CodeMirror?

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.

What is CodeMirror CSS?

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.


1 Answers

var codemirror = $('#YOUR_TEXTAREA_ID').nextAll('.CodeMirror')[0].CodeMirror;
codemirror.getDoc().setValue("");
like image 75
Mahdi Bashirpour Avatar answered Nov 10 '22 10:11

Mahdi Bashirpour