JSFiddle - React, Tailwind, and code Playground
HTML
<div id="mydiv" contenteditable="true">
editable follows:
</div>
JavaScript
function AppendSpan()
{
$('#mydiv').removeAttr('contenteditable').append('<span id="someid" contenteditable="true">Some TExt</span>');
//Then I want to handle the keypress event on the inserted span
$('#someid').keypress(function(event){alert('test');});
}
$(function()
{
$('#mydiv').keypress(function(event){AppendSpan();});
});