I have a contenteditable div containing a span and would like to trace the keydown events when typing in both the div itself and the span within the div.
Everything seems to work fine so far in firefox but in webkit browsers the div keydown event seems to override the span event. Is there a way to fire the keydown even for the span whilst it's within the div? (Demo)
HTML:
<div id="ceDiv" contenteditable="true" tabindex="0" onkeydown="return fnKeyDiv(event);">
put your cursor/caret in this contenteditable text and type some characters
or use the arrow keys
-- <span id="ceSpan" tabindex="0" onkeydown="return fnKeySpan(event);">
see what happens when typing inside this yellow text</span>
-- it's not clear to me : counter 2 only works when you click the mouse
inside the yellow text to put the caret there, not when the caret is moved inside
the yellow text by the arrow keys ..
AND : counter 2 does never work in WebKit !? (in FireFox it does)
</div>
<hr />
<span id="ST1" class="ST"></span> : counter 1 : typing in total text<br />
<span id="ST2" class="ST"></span> : counter 2 : typing in yellow "mytext"
JS:
var count = 0;
function fnKeyDiv(e) {
count++;
document.getElementById('ST1').innerHTML = count;
return true;
}
function fnKeySpan(e) {
count++;
document.getElementById('ST2').innerHTML = count;
return true;
}