Home > Software engineering >  How to display multiple CodeMirror correctly?
How to display multiple CodeMirror correctly?

Time:06-24

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});
});}

CodePudding user response:

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});
    });
}
  • Related