Javascript examples for CodeMirror:Configuration
Set Value to CodeMirror textarea
<html> <head> <title>Codemirror - Set Value</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script> <script type="text/javascript" src="https://codemirror.net/lib/codemirror.js"></script> <link rel="stylesheet" type="text/css" href="https://codemirror.net/lib/codemirror.css"> <script type="text/javascript" src="https://codemirror.net/mode/xml/xml.js"></script> <style id="compiled-css" type="text/css"> .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} </style> <script type="text/javascript"> $(window).load(function(){//from w ww . java2 s. co m $(document).ready(function() { var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/html", lineNumbers: true, }); $("#insert").click(function(){ var content = $("#content").val(); editor.setValue(content) }); }); }); </script> </head> <body> <br> <br> <input id="content" value="Type something "> <br> <br> <button id="insert">Insert Value</button> <br> <br> <textarea id="code" name="code"> <?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> </book> </catalog> </textarea> </body> </html>