Keydown() gets me down


#1


https://www.codecademy.com/courses/web-beginner-en-JwhI1/1/4?curriculum_id=50a3fad8c7a770b5fd0007a1#


Code was accepted but i don't see any change.


$(document).ready(function() {
    $('div').keydown(function() {
        $('div').animate({left:'+=10px'},500);
    });
});


#2

I solved it by myself by replacing keydown() 's selector with document like this. And it works now.

$(document).ready(function() {
    $(document).keydown(function() {
        $('div').animate({left:'+=10px'},500);
    });
});

#3

Keyboard events can only be bound to focusable elements such as form controls. In absence of any of these, then they are bound to the document.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.