jquery-uijquery-autocomplete

jquery ui autocomplete: count results


i would like to know if theres a way to count the number of results which are displayed when you type something in the textbox. Count the li-elements work, but i bet theres a smarter way. Thanks


Solution

  • I don't think this is possible directly using JQueryUI Events. I've looked for a way without success.

    All the events associated only return the element clicked (after the list is displayed), or information about the event (not about the list).

    You can see it here: http://jqueryui.com/demos/autocomplete/#event-focus

    What you said is the closest solution:

    $( "#tags" ).autocomplete({
      source: availableTags,
      open: function(event,ui){
        var len = $('.ui-autocomplete > li').length;
        $('#count').html('Found '+len+' results');
      }
    });