Doidgey Doidgey - 4 years ago 425
Javascript Question

How to kill a CodeMirror instance?

I'm using Codemirror v3.16 and I'm trying to figure out how I can kill an instance of my codemirror? Basically codemirror fires when a textarea opens in a modal on my page. Closing this modal, I need to kill the instance, else when I reopen the modal, I get two textareas.

Can anyone help?

Answer Source

If the CodeMirror instance was created with CodeMirror.fromTextArea, you can use its toTextArea method to copy the current contents to its "mirrored" text area and remove the instance.

Assuming your CM instance has the id of "CMEditor":

CM = document.getElementById('CMEditor');

Alternately, you could instantiate the CM instance outside of the modal, and just hide and show it when the modal opens.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download