javascript - Manipulate a dynamically generated html element in jquery -


i have little problem here. ¿how can manipulate dynamically generated html, in jquery?

i have function like:

generatesomething : function(destinationid,data){     result = $.dosomething(data)     $('#'+destinationid).html(data); } 

the script, in other point, receive through ajax array. naturally, iterate array like:

$.each(response, function(key, value){     thishtml = '<div id="div'+key'"></div>';     $('#myplaceholderdiv').html(thishtml)     //in point, need call first function     $.generatesomething('div'+key',data)     //but not works!!!! } 

how can manipulated generated div using function?

thanks in advance!

edit: in try clarify question, paste exact functions.

i made function. please not laugh @ code, newbie in jquery.

jquery.fn.extend({ /funciones generales/

piegraph : function(graficodestino,tipo,arraydatos,dato1,dato2,tooltiptemplate,labeltemplate){     var datapoints = [];     $.each(arraydatos, function(key, value){         var temporal = {};         temporal.label = value[dato1];         temporal.y = parseint(value[dato2]);         datapoints.push(temporal);     });     var opciones = {          animationenabled : true,         data : [{             type : tipo,             startangle : 0,             tooltipcontent : tooltiptemplate,             indexlabel : labeltemplate,             datapoints : datapoints,         }]      };     $('#' + graficodestino).canvasjschart(opciones); } 

this function works pretty well... if can give destination div it.

in other part of script, have ajax call:

generadisco: function(){     var datos = {         "accion":"generadisco"     };     $.ajax({            type: "post",         url: "blahblah.php",         data: datos,         datatype: "json",         success:function(response){              $.each(response, function(key, value){                 estehtml = '<div id="divdisco'+key+'"></div>                                     $('#discosplace').append(estehtml);                 //the div generated... when do...:                 $(this).piegraph('divdisco'+key,'pie', response[3],0,1, "{label} #percent%","{label} ");                 //nothing happens             });         }     }); } 

i found error in code:

$('#myplaceholderdiv').html(thishtml) $.generatesomething('div'+ key ,data) 

must be:

$('#myplaceholderdiv').html(thishtml); $.generatesomething('div'+key',data); 

also try add console.log(destinationid) in first line of function see passed argument (destinationid)


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -