Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created August 4, 2010 05:16
Show Gist options
  • Select an option

  • Save dieseltravis/507683 to your computer and use it in GitHub Desktop.

Select an option

Save dieseltravis/507683 to your computer and use it in GitHub Desktop.
reusable click simulator function for keypress event in jQuery
var pretendClick = function (e) {
if (e) {
var key = e.which || e.keyCode;
if (key && (key === 13 || key === 32)) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).trigger("click");
}
}
};
$("a").bind("click", function () {
// some click function
}).bind("keypress", pretendClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment