Michael Rader Michael Rader - 5 months ago 29
Javascript Question

Recognize the backspace and spacebar with jQuery

when a user clicks the spacebar or backspace I need to create a variable that stores the action so I can use it to manipulate an array. I want the backspace to delete a value in an array and the spacebar to create a space. How can I do this?

Answer

Maybe this can help you:

$('body').keyup(function(e){
   if(e.keyCode == 8){
       // user has pressed backspace
       array.pop();
   }
   if(e.keyCode == 32){
       // user has pressed space
       array.push('');
   }
});