javascript - jQuery: How to detect arrow key press only on certain element -


i new jquery , trying find way detect arrow key press (only , down). when searching online came across this post here.

this looks want detect arrow key press when user on element class (i.e. element has focus) added dynamically page.

specifically highlight corresponding list item when pressing or down arrow key on list focus.

is there way can achieved , work cross-browser ?

it looks happens automatically in case doesn't work , skips list items why thought can define separately.

example element:

<ul class="myclass" id="someid">    <li><a href="#">value1</a></li>    <li><a href="#">value2</a></li>    <li><a href="#">value3</a></li> </ul> 

many in advance help, mike

instead of

$(document).keydown(function(e) { 

in javascript code have

$(<selector>).keydown(function(e) { 

where <selector> points element want track.

update

better - since mention dynamically added elements, use delegation structure of event binding:

$(document).on("keydown", ".<yourclassname>", function(e) { 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -