2

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?

1 Answer 1

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

    }
    ...
}

Reading:

Sign up to request clarification or add additional context in comments.

2 Comments

And e = e || window.event;. quirksmode.org/js/keys.html might be interesting to read as well.
@David19801: Some browsers use the event parameter passed to the function, and some use window.event. jQuery makes cross browser stuff easy by taking care of that for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.