2

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.

0

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

I tried... $(document).keydown(function(e){ if (e.keyCode == 37) { $("#next").trigger('click'); } }); To trigger a link formatted similar to below... <a accesskey='n' href='URL'><img src='URL.gif' alt='Next >' title='Next >' id='next' /></a> ...and not having any luck. Any ideas?
@Derek: try putting the id #next in the A tag instead of the IMG tag.
@David Thanks for the help. Unfortunately I'm still unable to trigger a link via arrow keys after changing the location of the ID to the A tag. The code @jbochi shared works for displaying an alert, I'm just not able to figure out how to get this script to select and trigger a link.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.