David19801
David19801

Reputation: 11448

Jquery to javascript keypress event

I have the following in jquery code:

$(document).keypress(function (e) {
    if (e.keyCode == 13) {

    }
});

How can I make this into javascript so I do not need to load jquery everyime?

Upvotes: 2

Views: 124

Answers (1)

karim79
karim79

Reputation: 342625

document.onkeypress = function (e) {
    if (!e) var e = window.event;
    var keyCode = e.keyCode || e.which;
    if(keyCode == 13) {

    }
    ...
}

Reading:

Upvotes: 5

Related Questions