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 7736773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:49:43+00:00 2026-06-01T07:49:43+00:00

I am trying to set up an auto-complete search form with jQuery. I would

  • 0

I am trying to set up an auto-complete search form with jQuery.
I would like to hide the search results div when the field isn’t focused, however if someone tries to click a link within the results, they are unable to since it instantly becomes hidden, since the search field lost focus.
Here is the code:

HTML:

<form>
  <input type='search' id='search' placeholder='search' />
</form>
<div id='search-results' style='display:none'>
  <ul>
    <li><a href='#'>Example Result</a></li>
  </ul>
</div>

JavaScript

$("#search").keyup(function() {
  query = $(this).val();
  if(query.length > 2) {
    $("#search-results").html(get_search_results(query)).show();
  } else {
    $("#search-results").hide();
  }
});

$("#search").focus(function() {
  if($(this).val().length > 2) {
    $("#search-results").show();
  }
}); 

$("#search").blur(function() {
  $("#search-results").hide(); //makes it impossible to click results
});

How can I accomplish hiding the results when not in use, but still have them be clickable?

  • 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-06-01T07:49:44+00:00Added an answer on June 1, 2026 at 7:49 am

    I would recommend setting a function to check if the mouse is over the search-results div.
    Like so.

    // Have a global variable
    var hovered = false;
    

    Then have a function that changes it on rollover

    $("#search-results").bind("mouseover",function() {
        hovered = true;
    }).bind("mouseout",function() {
        hovered = false;
    });
    

    then in your function you check if the variable is true

    $("#search").blur(function() {
        if(!hovered) {
            $("#search-results").hide();
        }
        else {
            $("#search-results").bind("mouseup",function() {
                $("#search-results").hide();
            })
        }
    });
    

    Hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set up jQuery autocomplete in Rails 3.2.0. I have it
I'm trying to set my Auto Properties but they are non-static and so I
I'm trying to set up an auto-deploy from my springloops SVN through SFTP, but
Im trying set the single table inheritance model type in a form. So i
I am implementing a jquery autocomplete on a search form and am getting the
I would like to have a ComboBox control on a form which will be
Im trying to use a Web Service to set an Airport code using Jquery
I'm trying to create a custom UserControl that will mimic auto-complete as it works
I'm trying to make a search of some items with a jquery ui autocomple
I'm trying to enable auto complete for the command line in emacs mode. When

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.