Hi,

I need to capture the delete key event onclick on DIV. I wrote the below code using jQuery.

$("#DIVID").keydown(function(event){ // delete key works with IE
			  if(event.keyCode == 46)
			  {
				 // delete code goes here
			  }

This is working fine in IE but not on Mozilla, Safari.
Please do the needful.

Try this trick :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Window-target" content="_top">
<title>Free Live Help!</title>
<script type="text/javascript">
<!--
/******************************
Developed By DANIuser : essential -

 * Created : July 25th, 2009 -
 * Title : Eraser v1.0 -
 * This notice MUST stay intact for use - 
 * http://www.daniweb.com/forums/member383844.html
******************************/
var ie = (( !!document.all && !!!document.getElementById ) ? 1 : 0 );
onkeyup = function( e ) {
var xId = ["main"];
var xItem = [ ];
var element = ( function( elementId ) {
   var elementId = (( ie ) ? document.all[ elementId ] : document.getElementById( elementId ));
   return elementId;
} );
   for ( var x = 0; x < xId.length; x++ ) {
      xItem[ x ] = element( xId[ x ] );
   }
   var xTxt = xItem[ 0 ].innerText; 
   var xLen = xTxt.length; 
   var e = (( e ) ? e : window.event );
   var xCode = (( "keyCode" in e ) ? e.keyCode : (( "which" in e ) ? e.which : undefined ));
      if ( typeof( xCode ) !== "undefined" ) {
         if (( xCode === 46 ) && ( xLen > 0 )) {
         xItem[ 0 ].innerHTML = "<span style=\"background-color : #00FF00\">" + xTxt.replace( new RegExp( xTxt.substr( xLen - 1 ) + "$"), "" ) + "</span>";
         } return;
      } alert( "Please update your browser with the latest patch", "unsupported feature" );
      return false;      
};

// -->
</script>
</head>
<body>
<div id="main">Press the DELETE key</div>
</body>
</html>

hope it helps...

This article has been dead for over six months. Start a new discussion instead.