preventEvent( event )



This function cancels an event and prevents it from bubbling up.

Parameters:

  • event – reference to the event to cancel

Example:

The following can be used on the onkeydown event to restrict which keys can be pressed. 

function gradeKeys(event, element) {   var key = event.keyCode;   switch (key) {     case 65: // allow A     case 66: // allow B     case 67: // allow C     case 68: // allow D     case 70: // allow F     case 8: // allow backspace     case 46: // allow delete     case 37: // allow left arrow     case 39: // allow right arrow     case 40: // allow down arrow     case 38: // allow up arrow     case 13: // allow enter       break;     default: // disallow all other keys       preventEvent(event);   }  }