views:

16

answers:

1

I've seen thejQElement.toggle(fn1, fn2, fn3, fn4) would do the trick in case I wanted to click the element. I want it to sequencially fire the events on the tab keydown event.

Thanks

+1  A: 

You trigger .toggle() by triggering a click event, so just trigger that in a keydown event, like this:

jQElement.keydown(function(e) {
  var keyCode = e.keyCode || e.which; 
  if (keyCode == 9) $(this).click(); //tab key only
});

Alternatively, just use this same keyCode check and write your own .tabToggle() function, it wouldn't be difficult if you look at the source for .toggle().

You can view a quick .tabToggle() demo here, adjust if needed, but the concept's the same as .toggle() already does internally.

Nick Craver
@Nick: You are missing `e` in function parameter.
Sarfraz
@Sarfraz Ahmed: Fixed, adding a tabToggle method in a minute in case someone's curious
Nick Craver
Thanks again Nick
DanC