[Solved] “if (x == 100) alert” not working in combination with keydown function?


You should put the code inside the callback function, otherwise the nummer will just be 0.

$(document).keydown(function(e) {
    switch (e.which) {
    case 38:
        $("#object").stop().animate({
            top: "10" 
        }); 
        nummer = 0;
        break;
    case 40:
        $("#object").stop().animate({
            top: "200"
        }); 
        nummer = 100;
        break;
    }

   if (nummer == 100) {
        //do something it does have the protected class!
        alert("the object is at the bottom");
    }

})

0

solved “if (x == 100) alert” not working in combination with keydown function?