Search code examples
javascriptjquerykeypress

How to detect backspace key?


How can I also choose if e.which == 'backspace' ? at the moment, this function helps with showing a loader when info from a database is being retrieved, though i want the loader to show when the backspace is pressed.

field.focus().keypress(function(e) {
    e.which !== 0 ? loader.show() : loader.hide();
});

Solution

  •  field.focus().keyup(
       function(e){
         if(e.keyCode === 8)
           alert('backspace trapped')
       }
     )