user958414
user958414

Reputation: 385

clicking a HTML href with enter key without javascript

hi i have a div wrapped in image tag as below:

<div id="SubmitButtonDIV" style="position: relative; left: 70px; top: 15px"><img
id="btnDOB" alt="" src="PsychOImages/calculate-white.jpg"
onmouseover="this.style.cursor='pointer';" tabindex=4 /></div>

i want to use keyboard controls over it, i have set its TabIndex to 4 now when tab reaches this image contained in a Div i want to use Enter button for clicking it instead of a mouse click.

Is there a HTML property for doing it without using JavaScript?

Upvotes: 0

Views: 2002

Answers (2)

anothershrubery
anothershrubery

Reputation: 21003

$('#btnDOB').keydown(function(e) {
    if(e.keyCode == '13')
    {
        //Do your thing
    }
});

Upvotes: 0

samn
samn

Reputation: 2807

Why don't you just put an a href around the image and set the tabindex there?

Upvotes: 2

Related Questions