I want to capture the keystrokes on a table's cells. I have the following code that is working on IE but not on Firefox/Chrome.
<table id="testing" onkeydown="alert('testing')"><br />
<tr><td>testing</td></tr>` <br />
</table>
<br />
Any suggestion?
http://www.w3schools.com/jsref/jsref_onkeydown.asp specifies that most of the tags support onkeydown.
You need to set tabindex
property (eg tabindex="1"
) to some value, so it can identify that this table is keyboard selectable. That allows the keyboard event to be triggered. Following will work in firefox:
<table id="testing" onkeydown="alert('testing')" tabindex="0"><br />
<tr><td>testing</td></tr><br />
</table>
This appears to be an issue with Firefox and Chrome's interpretation of the specifications rather than your code. I just tried this myself and reproduced the issue.
The W3C specifications show that Table cells should support onkeydown but this doesn't appear to be supported by Firefox/Chrome currently, you could try reporting this as a Firefox bug through their website. You usually get some feedback as to why it's broken (or why they think it's not broken and won't fix it as I've had in the past)
Can I ask why you need to capture keystrokes on table cells?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With