Maxim Volkomorov
Maxim Volkomorov

Reputation: 313

jQuery set focus on autocomplete list element

How do I focus on the created autocomplete menu item:

 <ul id="ui-id-1" class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" ...>
    <li class="ui-menu-item" role="presentation">
<a id="ui-id-3" class="ui-corner-all" tabindex="-1">ONE</a>
    <li class="ui-menu-item" role="presentation">
<a id="ui-id-4" class="ui-corner-all" tabindex="-1">TWO</a>
<...>

I've tried to $('#ui-id-3').focus();

Have not effect. Generaly i mean custom autocomplete: https://forum.jquery.com/viewImage.do?fileId=14737000004279180&forumGroupId=14737000000003003

Upvotes: 1

Views: 1794

Answers (1)

Tejas Savaliya
Tejas Savaliya

Reputation: 638

Try this code:

$("#autocomplete").autocomplete({
    source: [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
        "Groovy",
        "Haskell",
        "Java",
        "JavaScript",
        "Lisp",
        "Perl",
        "PHP",
        "Python",
        "Ruby",
        "Scala",
        "Scheme"
    ],
    autoFocus: true 
});

http://jsfiddle.net/Bqujj/91/

Upvotes: 1

Related Questions