Pejman
Pejman

Reputation: 2636

JQuery capture keydown on check

Is there any way to capture the ENTER key on an <input> element of type checkbox?

<input type="checkbox" value="1" name="remember" />

I have tried this in JavaScript:

$('input').on('keydown',function(e){ console.log(e.which)});

and it is not working.

Upvotes: 2

Views: 850

Answers (1)

Praveen
Praveen

Reputation: 56509

Your code is good. One thing you have wrap it in $(document).ready..

$(document).ready(function () {
    $('input').on('keydown', function (e) {
        alert(e.which)
    });
});

check in JSFiddle

Upvotes: 4

Related Questions