<div id="div" contenteditable="true"></div>

<script>
div = document.getElementById("div");
div.focus();
document.execCommand("InsertText", false, "foo");
document.execCommand("Delete");
document.execCommand("Undo");
</script>
