How to display multiple CodeMirror correctly?

This code re-adds information only to the first block:

window.onload = function(e) {
document.querySelectorAll(".codemirror-textarea").forEach(el => {
    const [output] = document.querySelectorAll(".codemirror-textarea");
    const editor = CodeMirror.fromTextArea(output, {lineNumbers: true, readOnly: true});
});}

>Solution :

You are looping over the elements, but applies CodeMirror to the first element each time, use el in your loop.

window.onload = function(e) {
    document.querySelectorAll(".codemirror-textarea").forEach(el => {
        const editor = CodeMirror.fromTextArea(el, {lineNumbers: true, readOnly: true});
    });
}

Leave a Reply