Keydown works perfectly when I select document
, *
, body
or any particular element.
But when I add .not('.some-class')
, keydown works like this .not()
doesn't even exist. Maybe because of the way keydown affects children elements, but I'm not sure:
$('*').not('.some-class').on('keydown',function(e){
var key = e.charCode || e.keyCode;
if(key == 33 || key == 34 || key == 35 || key == 36 || key == 37 || key == 38 || key == 39 || key == 40 ) {
e.preventDefault();
} else {}
});
How to disable these keys for the whole document except for 1 child class?
edit: http://jsfiddle.net/umL139xw/2/
How to stop this unwanted scrolling while keeping ability to move caret with arrows?
edit2: complete solution thanks to Jason P and Kaiido