2

I have some input created dynamically in a web page and every input need an autocomplete options with ajax request. Every input have same class.

I created that for one input but when other inputs created by user the autocomplete not working for them.

I use something like below:

$('.class').autocomplete(options);

How can correct this problem?

1
  • 2
    Reinitialize autocomplete on newly added element...
    – Rayon
    Commented May 26, 2016 at 11:15

2 Answers 2

2

Function .live() is deprecated now.

var options = {
    source: ["ActionScript", "AppleScript"],
    minLength: 2
};
var selector = 'input.searchInput';
$(document).on('keydown.autocomplete', selector, function() {
    $(this).autocomplete(options);
});
1

Just add this in your ajax code after the code where you're adding new element

$('.newElement').autocomplete(options);

You need to initialize autocomplete the each dynamically added element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.