jQuery focus() doesn't actually focus

Topher Fangio's Avatar

Topher Fangio

26 Nov, 2010 05:21 PM

Hi Drew,

I'm attempting to use your fantastic AutoSuggest plugin on my site, and I've got it working pretty well. The only thing I'd like is to be able to automatically focus in on that particular field so that they can immediately type text without having to first click. In addition, I'm using the placeholder attribute (I've set the startText to be blank because I'm using the html5form jQuery plugin) and it doesn't seem to work unless you first click on the AutoSuggest input and then click off again, so I'm trying to automate this via jQuery.

Now, if I bind a function to the focus() event and just print out a message, I can see that the focus event is actually being called, but it's simply not focusing in on the input box (i.e. there is no cursor and I can't type). Similarly, firing the click() event calls focus, but doesn't actually focus.

Any idea where I should start looking?

Oh, and thanks very much for such an awesome autoSuggest! It's way way way better than the built-in one that jQuery provides :-)

  1. 1 Posted by Matt on 07 Sep, 2011 09:02 PM

    Matt's Avatar

    I encountered this too. The solution was to put the focus on the textbox inside the UL element. Make sure you set asHtmlID when setting up the plugin.

    For example, if asHtmlID is set to myAutoSuggest, then you would do this:

    $('#myAutoSuggest').focus();

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac