$(document).keydown event not triggered/caught on first click

$(document).keydown event not triggered/caught on first click

For some reason the very first time the user presses a key on the HTML page the click is not registered. But if I click one time or press a key then the second time I press a key it registers fine. Here is how the event handler is declared:



  1. .....................
  2. $(function()
  3. {
  4. .......................
  5. ......................
  6.  $(document).keydown(function(e)
  7.     {
  8.         alert('keydown event');
  9.       ...................................
  10.       ..................................
  11.       // Other stuff

The outcome of the code above is that the first time I press a key nothing happens. The second time I press a key I get the Alert statement 'keydown event'. Why is that?