I have integrated CodeMirror with below code,
<style>
.CodeMirror {
    border-top: 1px solid #888; 
    border-bottom: 1px solid #888;
}
</style>
<body>
    <textarea id="myCode"></textarea>    
    <script type="text/javascript">
      window.onload = function() {
        var myTextarea = $("#myCode")[0];
        editor = CodeMirror.fromTextArea(myTextarea, {
          lineNumbers: true
        });
      };
    </script>
</body>
It shows a normal textarea only, which doesn't look like an editor and the line numbers are missing. Please help me if anything I am missing.
When I replace the line var myTextarea = $("#myCode"); with var myTextarea = $("#myCode")[0], it displays the edotor as well. 
Look at this fiddle.
HTML:
<textarea id="code"></textarea>
JS:
var minLines = 5;
var startingValue = '';
for (var i = 1; i < minLines; i++) {
    startingValue += '\n';
}
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    gutter: true,
    lineWrapping: true,
    value: startingValue
});
//FIX FOR MIN LINES
//http://stackoverflow.com/questions/10380759/codemirror-minimum-lines-number
editor.setValue(startingValue);
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