Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery trigger key.Code event

how to trigger keyboard specif key.Code event with jQuery?

I woul like to trigger specifically backspace keyboard event

like image 637
itsme Avatar asked Sep 22 '11 13:09

itsme


2 Answers

var e = jQuery.Event("keydown");
e.which = 8; // some value (backspace = 8)
$("input").trigger(e);
like image 162
genesis Avatar answered Oct 04 '22 02:10

genesis


<body onkeydown="return inspectKeyCode(event);">

function inspectKeyCode(event)
{
  if(event.keyCode == 8){
     //Do whatever

     //For disabling  return false;

  }
}

By this you can cancel the backspace button.

like image 26
dhinesh Avatar answered Oct 04 '22 00:10

dhinesh