<li> is kept by the set_input() function, After getting data by using a getJSON(). But even bind function is not working. could anybody pls help me!
$(document).ready(function() { $.getJSON('sample1.php?', function(data){ $.each(data, function(i,j){ testA[j.id]=j.name; }); set_input('div_1','continent',testA); }); $('#'+div_D+' ul li').bind('click',function(){ $('#'+div_D+' input[type='text']').val($(this).text()); }) }); function set_input(div_D,name_N,Array_A){ $('#'+div_D).html('<input id='+name_N+'>'); var str='<ul>'; $.each(Array_A,function(m,n){ str +='<li>'+n+'</li>' }) $('#'+div_D+' input[type='text']').after(str); } This is JSON array: [ {'id':'0','name':'Africa'},{'id':'1','name':'Americas'},{'id':'2','name':'Asia'},{'id':'3','name':'Europe'},{'id':'4','name':'Oceania'} ]
You are trying to bind to an item which does not exist in the DOM yet.
Move
to the last line of the set-input function. i.e. to
P.S. You have quite a few typos.