javascript - Use .bind method for down arrow key -


i enabled alert show whenever scrolled down mouse in <div>

$('#divid').bind('mousewheel dommousescroll', function (event) {     if (event.originalevent.wheeldelta < 0 || event.originalevent.detail > 0)      {         alert('scroll down scroll');     } }); 

what equivalent .bind method can use alert whenever scrolled down down arrow key in <div>

my attempt (but doesn't work):

$('#section1').bind('onkeydown', function (event) {     if (event.keycode == 40) {         alert('scroll down arrow key');     } }); 

i'd highly appreciate help.

i've checked out solution from: javascript keycode values "undefined" in internet explorer 8 - this, can't seem have alert happen specific <div>, don't want effect lingering throughout whole document.

i using .bind() , not other method, it's because when <div> want .unbind() previous, because in <div> want new .bind()

henry problem **

'onkeydown'

above keyword html tag's event attribute

you can check out below reference link reference link 'onkeydown' keyword

key word have used bind key down that's

'keydown'

that's problem else code proper

and here try code.

$(document).on('keydown',function(e) {              var code = (e.keycode ? e.keycode : e.which);              if (code == 40) {                                    alert("down pressed");              } else if (code == 38) {                  alert("up pressed");              }          });

and here link working code can check out

working code

even working here .bind() event can check out code


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -