Reputation: 719
I'm using jquery autocomplete plugin for auto suggestions.
It loads only for the onload elements of the page.
How can I make it work for the elements loaded with jQuery through ajax?
Upvotes: 1
Views: 592
Reputation: 16115
Call $(...).autocomplete(...)
(again) after appending the elements e.g. in the success callback of the ajax.
E.g.:
$(...).ajax({
...
success: function(respond) {
$(...).append(respond); // add new elements
$(...).autocomplete(...); // add autocomplete to them
}
...
});
P.s.: If you have an autocomplete element onload and only want to change their options, you can use the source
parameter of automplete to get the values dynamically (without setting autocomplete again).
Upvotes: 3