Created
September 5, 2021 04:50
-
-
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 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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