Why doesn't the crash work?

This simple code does not work! http://jsfiddle.net/FPcFn/

$(document).keydown(function(e){ switch (e.which){ case 37: alert("37"); } }); 

Why? What could go wrong?

0
source share
2 answers

It works. Click in the output window and press the left arrow.

+2
source

Use window instead of document .

 $(window).keydown(function(e){ .. } 

PS: Recommended to use document . keydown event is available both with documents and with a window. Take a look at the tables.

+4
source

Source: https://habr.com/ru/post/903823/


All Articles