Demo is here
I have a contenteditable div. I want the functionality in the div as follows:
When I click on red anchor tag, the new text that I will write will be
This is what I did:
$("#red").click(function () {
$("div").html($("div").html() + "");
});
$("#blue").click(function () {
$("div").html($("div").html() + "");
});
$("div").keypress(function (e) {
e.preventDefault();
$("div > span:last-child").text($("div > span:last-child").text() + String.fromCharCode(e.which));
});
Here is the JSFiddle