3

I'm using jQuery bind for click event on div elements. I want to make it accessible, so I assigned tabindex for div. Which is probably not XHTML valid, but at least tab is stopping where I want. The problem is, that pressing ender key is not triggering event in Firefox (5). In opera it works. Here is the example:

http://jsfiddle.net/NSpb3/13/

Input works for both click and enter key.

Thank you.

Jozef Mera
  • 615
  • 1
  • 6
  • 20
  • Interesting, should work according to specs. `This means that an element that is only focusable because of its tabindex attribute will fire a click event in response to a non-mouse activation (e.g. hitting the "enter" key while the element is focused).` http://www.w3.org/TR/html5/editing.html – pimvdb Jul 26 '11 at 11:52

3 Answers3

0

hey try this http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/

And code: http://jsfiddle.net/NSpb3/17/

Tom
  • 9,275
  • 25
  • 89
  • 147
0

You're binding 'click', which is NOT a key press? If you wan't to register the enter-key for you div, you should bind the keyup event and check if the user has pressed enter.

Thor Jacobsen
  • 8,621
  • 2
  • 27
  • 26
0

There's nothing in your code that binds a key press event to the div. This works:

http://jsfiddle.net/NSpb3/16/

maxedison
  • 17,243
  • 14
  • 67
  • 114
  • The problem of this is, that it fires the event twice when enter is hitted for example in Opera as jQuery is "trying" to be accessible and binds also keyboard events when binding click. – Jozef Mera Jul 26 '11 at 12:26