Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript: Original target of onkeyup()
    primarykey
    data
    text
    <p>I'm having a contentEditable field with many dynamically inserted span.</p> <p>When I use the getTarget() from an onclick() event I'm getting the target as the respective span but with onkeyup() and onkeydown() it gives the target as the div in which the function is called from ( I'm using bubbling to capture the events (if I'm correct))</p> <pre><code>function getTarget(e) { var targ; if (!e) var e = window.event; if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement; if (targ.nodeType == 3) // defeat Safari bug targ = targ.parentNode; return targ; } </code></pre> <p>Could someone point out why this is happening? Thank You</p> <p>Note: In fact , I just noticed that span is not accepting onkeydown,onkeyup or onkeypress. Only onclick event is triggered.How can I make span accept key event?</p> <pre><code>&lt;div class="myedit" onclick="setcontext(event);" onkeydown="getCursorPos();checkmarkup(this,event);" contentEditable="true" &gt; &lt;span class="context global" &gt;global &lt;br/&gt; &lt;span class="context function" &gt; fun1 hi bye &lt;/span&gt; &lt;div&gt; &lt;span class="context function"&gt; fun2 &lt;/span&gt; &lt;/div&gt; &lt;/span&gt; &lt;/div&gt; </code></pre> <p>This is the HTML part. Note that I can edit the text "global" or "fun1 hi bye" or "fun2" by clicking on them or moving the cursor to them. Correct me if I'm wrong, but as far as I understand <code>span</code> is able to receive key events (as it is able to change its contents) so it should be raising the key events. Also, even if I add <code>contenteditable='true'</code> and <code>onkeydown="alert('keytest')"</code>on each <code>span</code> it still doesn't raise the event.</p> <p>If in case it is not possible to capture key events on <code>span</code> then is there any other element that I could use that would capture key events but wouldn't change the structure?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload