views:

296

answers:

1

I have a standard textbox and I've got jQuery on the page. I want to act when the user types a space into the textbox, I am however unsure of how to do this.

Can anybody give me a hand with this please?

+5  A: 
var KEYS = {
    SPACE: 32
};

$("#textbox").keyup(function(e) {
    if (e.keyCode === KEYS.SPACE) {
        console.log("Space key pressed");
    }
});

References:

Ionuț G. Stan