javascript - How do you append to a div name that is being dynamically created in a for loop with jquery? -
i'm trying this:
var size = skillsarray.length; (i = 0; < size; i++) { var divstring = "'#skill" + +"'"; $(divstring).append(skillsarray[i]); }
to start out prototype, skillsarray had 5 values. javascript this:
$('#skill0').append(skillsarray[0]); $('#skill1').append(skillsarray[1]); $('#skill2').append(skillsarray[2]); $('#skill3').append(skillsarray[3]); $('#skill4').append(skillsarray[4]);
my html this:
<div id='skill0'></div> <div id='skill1'></div> <div id='skill2'></div> <div id='skill3'></div> <div id='skill4'></div>
and worked fine.
now want work larger dynamically sized arrays, want use loops.
so first step write html div tags out in javascript loop, worked:
(i=0; i<size; i++) { html += "<div id='skill" + + "'></div>"; }
before tried step 2 question about, did show first 5 skills fine, , every skill after blank. (to expected since hadn't updated javascript yet append each div, still did first 5.)
so, ready try step 2 , use loop appends. how can this? code pasted in @ top did not fill each div @ all.
thanks in advance help! -holly
try removing single quotes in line : var divstring = "'#skill" + +"'";
this:
var divstring = "#skill" + i;
Comments
Post a Comment