JSFiddle - React, Tailwind, and code Playground

by lichangwei

HTML

<div id="mydiv">
editable follows:
</div>

CSS

#someid{
 outline:1px solid #ccc;
}

JavaScript

function AppendSpan()
{
    $('#mydiv').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){event.stopPropagation();alert(this.id);});
    $('#mydiv').keypress(function(event){alert(this.id);});
}

AppendSpan();