Bind jQuery UI autocomplete using .live() Bind jQuery UI autocomplete using .live() jquery jquery

Bind jQuery UI autocomplete using .live()


jQuery UI autocomplete function automatically adds the class "ui-autocomplete-input" to the element. I'd recommend live binding the element on focus without the "ui-autocomplete-input"class to prevent re-binding on every keydown event within that element.

$(".foo:not(.ui-autocomplete-input)").live("focus", function (event) {    $(this).autocomplete(options);});

Edit

My answer is now out of date since jQuery 1.7, see Nathan Strutz's comment for use with the new .on() syntax.


If you are using the jquery.ui.autocomplete.js try this instead

.bind("keydown.autocomplete") or .live("keydown.autocomplete")

if not, use the jquery.ui.autocomplete.js and see if it'll work

If that doesn't apply, I don't know how to help you bro


Just to add, you can use the .livequery plugin for this:

$('.foo').livequery(function() {    // This will fire for each matched element.    // It will also fire for any new elements added to the DOM.    $(this).autocomplete(options);});