Here is the full page:
<html>
<head>
<title>Test</title>
<style type="text/css">
.edit { border: 1px solid blue; font-size: 20pt }
</style>
<script type="text/javascript">
function clean(id) {
setTimeout('clean2("'+id+'")', 1)
}
function clean2(id) {
el=document.getElementById(id)
off=window.getSelection().anchorOffset
el.innerHTML = el.innerHTML.replace(/(<([^>]+)>)/ig,"");
el.innerHTML = el.innerHTML.replace(/([0-9])/ig,"<font color='red'>$1</font>");
return false;
}
</script>
</head>
<body onload="document.getElementsByClassName('edit')[0].focus()">
<h1>Type in here</h1>
<div id="e1" class="edit" contentEditable="true" onkeyup="clean('e1')"></div>
</body>
</html>
The goal here is to highlight all numbers in red. (In the future I will actually use a little more complicated coloring rules). Currently this color substitution is happening, but as soon as you add a number to the box, focus is lost.
Any hints? (Using Chorme dev)