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.
Asked
Active
Viewed 8,755 times
2 Answers
3
$('a').trigger('click');

David Hellsing
- 106,495
- 44
- 176
- 212
-
I tried... $(document).keydown(function(e){ if (e.keyCode == 37) { $("#next").trigger('click'); } }); To trigger a link formatted similar to below...
...and not having any luck. Any ideas? – Derek Lerner Dec 31 '09 at 23:00
-
@Derek: try putting the id #next in the A tag instead of the IMG tag. – David Hellsing Jan 01 '10 at 10:49
-
@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. – Derek Lerner Jan 01 '10 at 18:45