You can trigger() click the event of any item when the enter key is pressed. Example:
$(document).keypress(function(e) { if ((e.keyCode || e.which) == 13) { // Enter key pressed $('a').trigger('click'); } }); $('a').click(function(e) { e.preventDefault(); // Link clicked });
Demo: http://jsfiddle.net/eHXwz/1/
You just need to figure out which specific element triggers the click, but it depends on how / what you do. I will say that I really do not recommend this, but I will give you the benefit of doubt.
The best option, in my opinion, would be focus() link to be clicked on, and let the user press the enter key to fire the click event anyway.
I would like to focus on the link, but donโt know how to do this, can you explain?
Just use $(element).focus() . But again, you need to be more specific and have a way to determine which element should receive focus, and when. Of course, the user can take actions that cause the link to lose focus, for example, clicking elsewhere. I have no idea what your application does or works like that, so just do what you think is best, but remember that users already expect certain behavior from their browsers and most likely they wonโt understand that they need to press enter if only you tell them.
If you prefer to use the โhit enterโ method instead of focusing the link, you most likely want the bind() and unbind() functions, so they wonโt be called. This is necessary.
Connected:
source share