JSFiddle - React, Tailwind, and code Playground
HTML
<div class="parent" contenteditable="true">
Parent div text.
<span class="child" contenteditable="true">First child span text.</span>
<span class="child" contenteditable="true">Second child span text.</span>
<span class="child" contenteditable="true">Third child span text.</span>
</div>
<div id="console"></div>
CSS
.parent {
width: 200px;
height: 200px;
background-color: #F7F7F7;
border: 1px solid black;
}
.child {
background-color: khaki;
margin: 0 2px;
}
#console {
background-color: black;
width: 202px;
height: 20px;
color: white;
clear: both;
}
JavaScript
$(document).on( 'keyup', '.parent', function() {
//do stuff
$('#console').html( 'Parent keyup event fired.' );
});
$(document).on( 'keyup', '.child', function(e) {
//do stuff
$('#console').html( 'Child keyup event fired.' );
e.stopPropagation();
});