ace editor onchange not working
-
21-12-2019 - |
Question
i'm working on a code playground using ace editor and i am trying to use ace editor onChange but nothing happens when I type.
my code is
<style>
html{padding:0px}
#editor {
border-radius:5px;
width:500px;
height:100%
}</style>
<a href="#" onclick="update()">go</a>
<div id="editor" onChange="update()">
function foo(items) {
var x = "All this is syntax highlighted";
return x;
}
</div>
<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.getSession().setUseWorker(false);
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/html");
editor.getSession().on('change', function() {
update()
});
</script>
<script>;
new function update()
{
var ace = editor.getSession().getValue();
var divecho = document.getElementById("output");
divecho.innerHTML=ace
}</script>
<div id="output"></div>
Any help will be greatly appreciated
Solution
new function update()
should be
function update()
Also it is not wise to use ace as a local variable when it is a global.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow