SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jquery hotkeys behaviour

    I am a fairly decent javascript programmer, but do not have a deep understanding of the DOM, this question should be fairly simple for any good programer, I hope.

    I am trying to use the Jquery.Hotkeys lib. here's what I noticed:

    if I do:

    Code:
    $(document).ready( function(){
    $(document).bind('keydown', 'ctrl+q', alertworld);
    });
    It works perfectly. but when I do

    Code:
    $(document).bind('keydown', 'ctrl+q', alertworld);
    It binds every single keydown press to the alertworld function. I just want to understand why it behaves so. I imagined it should work just fine in the second code example. Please help. thanx in anticipation

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by mandin View Post
    It binds every single keydown press to the alertworld function. I just want to understand why it behaves so. I imagined it should work just fine in the second code example. Please help. thanx in anticipation
    The tests that I tried seem to trigger on keydown correctly for both occasions.

    The only reason why it would trigger incorrectly is if the binding occurs before the hotkeys library has loaded.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Paul,

    I was confused at the behaviour, and yes you are right.. i moved the line that included the jquery.hotkeys Script some lines higher.. and the error stoped..

    I really appreciate your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •