I'm have an autocomplete function in JQUERY and a function that add an input in javascript.The problems is when I add the input, the autocomplete function doesn't work for it.
This is my autocomplete function in jquery:
$(function() {
$(".espaciado").autocomplete({
source:"/inicio/api/get_asesores/",
function (event, ui) { //item selected
AutoCompleteSelectHandler(event, ui);
},
minLength: 1,
});
});
function AutoCompleteSelectHandler(event, ui)
{
var selectedObj = ui.item;
}
This is my javacript function with which I add the input
var id= 2
function AgregarAsesor(clicked_id) {
var td = document.getElementById('scrollbar')
var asesorID = "asesor_" + id;
var cell=document.createElement("div");
cell.id = id;
adviserText = document.createElement("input");
adviserText.setAttribute("type","text");
adviserText.setAttribute('class', "ui-widget espaciado");
adviserText.setAttribute('id',asesorID);
var addadviser=document.createElement("i");
addadviser.id ="añadir_"+id;
addadviser.setAttribute("onclick","AgregarAsesor('"+id+"')");
addadviser.setAttribute('class', 'fa fa-plus espacio');
cell.appendChild(adviserText);
cell.appendChild(addadviser);
td.appendChild(cell);
id = id + 1;
};
and this is who the autocomplete is in the input that alredy exists
<input type"text" class="ui-widget espaciado" id="adviser_1"> <i id="añadir_1" class="fa fa-plus espacio" aria-hidden='true' onclick="AgregarAsesor(this.id)"></i>
How Can I do to add the autocomplete function to the dinamically added inputs ?