javascript - Writing a for loop to create divs -


what trying write loop create number of divs. number of divs depends on information have in database. example there 15 checkboxes, need loop create div each checkbox user clicked. i'm not worried mysql side of things right now, i'm focusing on loop.

so have main div 800px wide. let's user clicks 8 checkboxes, want figure out how write loop create 2 rows of 4 divs, each 200px wide. 4 divs on each row. doesn't matter in div right need know how tackle this.

any ideas lead me in right direction?

here code:

$(document).ready(function(){     for(i = 0; < (the number of checkboxes clicked); i++) {         $('body').append('<div id="div'+ +'" />');     } }); 

then div have same css code width 200px blah blah blah...

i guess need checkboxes clicked database , make div each checkbox.

why not use css this?

<input type="hidden" id="checkboxcount" value="[# of checkboxes checked]" />  <div class='container'><!-- append html here--></div>  $(document).ready(function(){     for( var = 0; < parseint(document.getelementbyid('checkboxcount').value, 10); i++) {         $('.container').append('<div class="ckbdiv" id="div'+ +'" />');     }  });  .container { width: 800px; } .ckbdiv { float: left; width: 200px; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -