How to generate id for dinamic div tag using php or jquery?
example: php generates 36 divs, how to set each div unical id from 1-36?
How to generate id for dinamic div tag using php or jquery?
example: php generates 36 divs, how to set each div unical id from 1-36?
How about:
for($i = 1; $i < 37; $i++)
{
echo "<div id='div-$i'></div>";
}
Edit: 2D version, even though you have one, I didn't realise this is what you wanted.
for($x = 1; $x <= 36; $x++)
{
for($y = 1; $y <= 36; $y++)
{
echo "<div id='div-$x-$y'></div>";
}
}
Try this:
You can use PHP:
<?php for($i = 0; $i <= 36; $i++) { ?>
<div id="div<?php echo $i; ?>"></div>
<?php } ?>
or JavaScript:
for(var i = 1; i <= 36; i++) {
var div = document.createElement('div');
div.id = 'div' + i;
document.body.appendChild(div);
}