I have a div whose contenteditable property is set to true. How can I get kids to respond to keyboard events? It seems that the only way is to capture the events in the parent div and define the child using the selection apis. Is there a better way? In particular, can I connect a keyboard event handler to child elements? Did I miss something?
Attached example code that illustrates the problem. We hope that the comments in the code are quite explanatory.
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<div id="editable" contentEditable='true' style='height: 130px; width: 400px; border-style:solid; border-width:1px'>
<span id="span1" onkeypress="alert('span1 keypress')">test text 1</span>
<span id="span2" > test text2</span>
<span id="span3" onclick="alert('span3 clicked')">test text 3</span>
</div>
</BODY>
</HTML>
source
share