I am trying to customize the colors and widths of multiple div elements using arrays and a for loop in my HTML code. However, I am having trouble figuring out how to properly implement this. Specifically, I want 5 divs on the page with different background colors and widths.
If anyone has experience with this type of task and can offer some guidance, I would greatly appreciate it. Thank you!
<html>
<head>
<title>Customizing Div Elements</title>
<script type="text/javascript">
var colorArray = Array("#F00","#FF0","#0F0","#0FF","#00F");
var widthArray = Array("20", "40", "60", "80", "100");
{
for (i=0; i<5; i++)
{
document.getElementById('div'+i).style.backgroundColor = colorArray[i];
document.getElementById('div'+i).style.width = widthArray[i];
}
}
</script>
</head>
<body>
<div id="div1">div1</div>
<div id="div2">div2</div>
<div id="div3">div3</div>
<div id="div4">div4</div>
<div id="div5">div5</div>
</body>
</html>