P Coder P Coder - 2 months ago 7
jQuery Question

How to remove an autocomplete once added to an element?

After I add a autocomplete to an element like:

commObj=$("#communityName").autocomplete("auto_commName_backend.php",
{'onItemSelect': handleItemSelect}, {'extraParams': 'ndo' + ndo});


Is there a way I could disable it or remove the autocomplete for the element dynamically?

I am using modified jquery autocomplete plugin from Dylan Verheul.
http://www.pengoworks.com/workshop/jquery/autocomplete_docs.txt

Answer

You can remove the autocomplete behaviour by using following line of code:

if (jQuery(control).data('autocomplete')) {
  jQuery(control).autocomplete("destroy");
  jQuery(control).removeData('autocomplete');
}