I’m creating a <select> replacement using jQuery to replace it with divs and links.
Now I want to filter it when I start to type something with the new select open.
Like Google Translate does on the language selector.
Do you have any advice how do i proceed?
I started something with:
$(document).bind('keypress', function(event) {
//...
});
But I capture only single keys, not the whole typed string.
Important:
- I don’t have an
<input />to detect thekeypressorkeyupevents on it - I prefer not to create this
<input />since I want to use only<div>‘s and<a>‘s on the “new select” - Lately I’ll need to navigate on the open select with arrow keys + enter to select the option with my keyboard
You could achieve this by ‘listening’ about what is pressed on the window, and then detecting the particular letter/string pressed, search through items list and if you find it change its css properties or add a new ‘selected’ class i.e. (demo => http://jsfiddle.net/steweb/mC6tn/ ..try pressing whatever 🙂 and added after something found press left or right btns, or enter) :
JS: (supposing that each element you want to find something into and select it has class ‘elem’)
EDIT added left/right/enter keys handling