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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:38:10+00:00 2026-05-29T10:38:10+00:00

I have successfully attached autocomplete to the span tag with click event handler via

  • 0

I have successfully attached autocomplete to the span tag with click event handler via

$('#myspan').click(function() {
 var target = $('#myvalue');
 $(this).autocomplete({
                minLength:0,                
                source: ['Apple','Banana','Strawberry'],
                select: function(event, ui) {
                    target.html(ui.item.value);
                }
            });
 $(this).autocomplete("search","");   
});​

The problem is, since there is no input box, no blur() event occurs and autocomplete remains on the screen if user clicks outside of the selector.
To see the effect, click subsequently on “Select first”, then “Select second” without actually choosing an item: http://jsfiddle.net/gtcZb/

  • 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-29T10:38:11+00:00Added an answer on May 29, 2026 at 10:38 am

    Couldn’t you just make your span focusable? Addind a tabindex attribute to it will make it focusable (if you don’t want it gaining focus through Tab and Shift+Tab, use "-1" as value).

    I couldn’t run your example (jsFiddle seems to be offline), but I tried to reproduce it and made it work – mostly:

    HTML

    <span id="myspan" tabindex="-1">abcd</span>
    <span id="myvalue"></span>
    

    JavaScript

     $('#myspan').click(function() {
         var target = $('#myvalue');
         $(this).autocomplete({
                        minLength:0,                
                        source: ['Apple','Banana','Strawberry'],
                        select: function(event, ui) {
                            target.html(ui.item.value);
                        }
                    })
         $(this).autocomplete("search","").focus();
     }).blur(function() {
         var $this = $(this);
         setTimeout(function() { $this.autocomplete("close") },0);
     });​        
    

    It’s not perfect – sometimes the autocomplete doesn’t disappear, even when the span loses focus, and I couldn’t figure out why. But it’s a start…

    Edit: I forgot the setTimeout closure… Now it should work for all cases.

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

Sidebar

Related Questions

I have a form with a submit button. I have attached a click event
I have configured datepicker to activate as following $(function () { $(.editable_datepicker).click(function (event) {
I have some GLSL shaders that are compiling correctly, and being successfully attached to
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I have successfully implemented interop beftween Win32 application and managed .Net dll as described
I have successfully upgraded an MFC application which was compiled with an old version
I have successfully used the Excel and Word addin templates in Visual studio 2008
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed
I have successfully compiled lua in my mac. It works. It runs. Now, I

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.