Skip to content

Instantly share code, notes, and snippets.

@xuncheng
Last active January 1, 2016 23:58
Show Gist options
  • Save xuncheng/8219600 to your computer and use it in GitHub Desktop.
Save xuncheng/8219600 to your computer and use it in GitHub Desktop.
Keyboard Navigation between Input Fields using JQuery: up/down key
// Need dom_element_find.js
// https://gist.github.com/xuncheng/8219581
jQuery(document).ready(function(){
$('input[type=text]()').bind('keyup', function(evt) {
if (evt.keyCode == 40) {
// down key
var target = $('input[type=text]()').elementAfter(this)
if (target) {
target.focus();
}
} else if (evt.keyCode == 38) {
// up key
var target = $('input[type=text]()').elementBefore(this)
if (target) {
target.focus();
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment