Different actions on multiple Keydown event

Posted by Billy Mitchell on Stack Overflow See other posts from Stack Overflow or by Billy Mitchell
Published on 2010-06-02T04:33:21Z Indexed on 2010/06/02 4:43 UTC
Read the original article Hit count: 216

Filed under:
|

Okay, so my question (im hoping) is fairly simple. I want to know what to do so that I can create different events for the same keycode. For instance Id like to fade out a div and fade a new one in on the first keypress, then fade that one out and fade a new one in on keypress.

Thanks!

$(document).keydown(function() {
  if (event.keyCode == '40') {

    $('.div-1').fadeOut("slow")
    $('.div-2').fadeIn("slow")

   // I'd like this event to occur on the Second keydown

    $('.div-2').fadeOut("slow")
    $('.div-3').fadeIn("slow")
   }  
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery