jqueryautocompletejquery-autocompletejquery-ui-autocomplete

jQuery - How to check if autocomplete is bound


Sometimes I need to know if an input field already has autocomplete bound to it. I haven't found any other way to do this other than:

$input.hasClass('ui-autocomplete-input')

Then I discovered that elements with autocomplete has an attribute like this:

<input autocomplete="off">

This however never seems to be set to on, and I can't find any documentation about this attribute.

Question: What is the best/correct way to check if autocomplete has been bound to an element?


Solution

  • you can also use the data property

    var check = $input.data('ui-autocomplete') != undefined;