Goal: Attach a keydown event handler to a contenteditable span that is the child of a contenteditable div.
Problem: If you type in the span the parent event is triggered not the childs. What I want is the child to trigger so I can grab the text. I only want THAT contenteditable child as there will be many.
HTML/JS is below and the fiddle link is here: http://jsfiddle.net/aBYpt/4/
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>
JavaScript/jQuery
$(document).on( 'keyup', '.parent', function() {
$('#console').html( 'Parent keyup event fired.' );
//do stuff
});
$(document).on( 'keyup', '.child', function() {
$('#console').html( 'Child keyup event fired.' );
//do stuff
});
**Note: Event handling is delegated to document because elements are dynamically added.