Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5838291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:27:08+00:00 2026-05-22T11:27:08+00:00

I’m creating a <select> replacement using jQuery to replace it with divs and links.

  • 0

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 the keypress or keyup events 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:27:09+00:00Added an answer on May 22, 2026 at 11:27 am

    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’)

    var whatYouAreSearching = $('<div class="searching-string"></div>'); //just to see what string you're typing
    $(document.body).append(whatYouAreSearching);
    
    function search(what){
        what = what.toLowerCase();
        $('.elem').removeClass('selected'); //reset everything
        $.each($('.elem'),function(index,el){
            if($(el).html().toLowerCase().indexOf(what) > -1){
                $(el).addClass('selected');
                return false; //found, 'break' the each loop
            }
        });
    }
    
    var letterPressed = [];
    var timeOutResetLetters = null;
    
    $(window).keypress(function(e) {
        clearTimeout(timeOutResetLetters); //clear timeout, important!
        timeOutResetLetters = setTimeout(function(){ //if 500 ms of inactivity, reset array of letters pressed and searching string
            letterPressed = []; 
            whatYouAreSearching.html('');
        },500);
        letterPressed.push(String.fromCharCode(e.keyCode)); //look at the comment, thanks Niclas Sahlin 
        whatYouAreSearching.html(letterPressed.join('')); //show string
        search(letterPressed.join('')); //and search string by 'joining' characters array
    });
    

    EDIT added left/right/enter keys handling

    $(window).keydown(function(e){ //left right handling
        var currSelected = $('.elem.selected');
    
        if(e.keyCode == "37"){ //left, select prev
            if(currSelected.prev() && currSelected.prev().hasClass('elem')){
                currSelected.prev().addClass('selected');
                currSelected.removeClass('selected');   
            }
        }else if(e.keyCode == "39"){ //right, select next
            if(currSelected.next() && currSelected.next().hasClass('elem')){
                currSelected.next().addClass('selected');
                currSelected.removeClass('selected');   
            }
        }else if(e.keyCode == "13"){ //enter
           $('.entered').remove();
           $(document.body).append(currSelected.clone().addClass('entered'));
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.