18
rated 0 times
[
24]
[
6]
/ answers: 1 / hits: 40107
/ 12 Years ago, mon, june 18, 2012, 12:00:00
I want to create a grid of HTML divs that will have the same number of rows and columns
but with the number of rows/columns being based on a particular number
that would be passed to the Javascript function.
e.g. if the number is 3 the grid will be 3 rows and 3 columns
if the number is 4 the grid will be 4 rows and 4 columns..etc
in the case of 3 the outputted code would need to look something like:
<div class=row>
<div class=gridsquare>1</div>
<div class=gridsquare>2</div>
<div class=gridsquare>3</div>
</div>
<div class=row>
<div class=gridsquare>4</div>
<div class=gridsquare>5</div>
<div class=gridsquare>6</div>
</div>
<div class=row>
<div class=gridsquare>7</div>
<div class=gridsquare>8</div>
<div class=gridsquare>9</div>
</div>
What is a good way of iterating through javascript so that the correct elements
can be identified to add the row div opening or closing tags (?)
More From » html