Skip to content

Instantly share code, notes, and snippets.

@naveen17797
Created September 5, 2021 04:50
Show Gist options
  • Save naveen17797/d78d7227a19f4eab6f7fa9859661565e to your computer and use it in GitHub Desktop.
Save naveen17797/d78d7227a19f4eab6f7fa9859661565e to your computer and use it in GitHub Desktop.
A piece of code for users who prefer to use keyboard ( search field focus from shortcut )
document.onkeypress = function(evt) {
evt = evt || window.event;
var charCode = evt.keyCode || evt.which;
var charStr = String.fromCharCode(charCode);
if ( charStr !== '/' ) {
return;
}
var inputs = document.querySelectorAll('input[type=text]')
if ( inputs.length === 0 ) {
return;
}
inputs[0].focus()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment