Derek Lerner
Derek Lerner

Reputation: 23

Arrow keys keyboard navigation with Jquery

In Jquery I would like to know how to trigger/click an a href... link that's within a .php page. This page is dynamically generating two links that I'd like to trigger using left and right keyboard arrow keys for paging next and back through a site. The links are two images within two divs. I attempted to use this but was unable to get to work due to how the links are being created.

Upvotes: 2

Views: 8805

Answers (2)

David Hellsing
David Hellsing

Reputation: 108530

$('a').trigger('click');

Upvotes: 3

jbochi
jbochi

Reputation: 29654

I could do something like this:

$(document).keydown(function(e){
    if (e.keyCode == 37) { 
       alert( "left pressed" );
       return false;
    }
});

Character codes:

37 - left

38 - up

39 - right

40 - down

Upvotes: 8

Related Questions