javascript - jquery autocompleter is not working for dynamically added textboxes -
here fiddle jquery ui autocompleter working on page load first textbox, after ading more textbox same classname, autocompleter not working.
can me please
$(document).ready( function(){ var availabletags = [ "actionscript", "applescript", "asp", "basic" ]; $( ".lang" ).autocomplete({ source: availabletags }); $('#addrow').click( function() { var curmaxinput = $('input:text').length; $('#rows li:first') .clone() .insertafter($('#rows li:last')) .find('input:text:eq(0)') .attr({'id': 'ans' + (curmaxinput + 1), 'value': '', 'name': 'ans' + (curmaxinput + 1) }) .parent() .find('input:text:eq(1)') .attr({ 'id': 'ans' + (curmaxinput + 2),'value': '', 'name': 'ans' + (curmaxinput + 2) }); $('#removerow') .removeattr('disabled'); if ($('#rows li').length >= 5) { $('#addrow') .attr('disabled',true); } return false; }); $('#removerow').click( function() { if ($('#rows li').length > 1) { $('#rows li:last') .remove(); } if ($('#rows li').length <= 1) { $('#removerow') .attr('disabled', true); } else if ($('#rows li').length < 5) { $('#addrow') .removeattr('disabled'); } return false; }); });
when add new .lang
element don't associate autocomplete too, because binding done on document ready.
so created function , called in document ready, in $('#addrow').click
:
function addautocomplete() { var availabletags = [ "actionscript", "applescript", "asp", "basic"]; $(".lang").autocomplete({ source: availabletags }); } addautocomplete();
i modified code , create fiddle. hope helps.
Comments
Post a Comment