Skip to content

Instantly share code, notes, and snippets.

@oslego
Created February 8, 2011 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oslego/816721 to your computer and use it in GitHub Desktop.
Save oslego/816721 to your computer and use it in GitHub Desktop.
Method for handling keypress events on non-input elements in Safari (and other webkit-based browsers)
var div = document.getElementById("demo");
div.setAttribute("tabIndex", 0);
div.focus();
div.addEventListener("keypress", function(e){
console.log(e.keyCode);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment