JSFiddle - React, Tailwind, and code Playground
HTML
<div id="main">
<div>1</div>
<div>2</div>
</div>
CSS
.foo1
{
color:blue;
}
.foo2
{
color:red;
}
JavaScript
var elem = document.getElementById("main");
var childDivs = elem.getElementsByTagName("div");
for (var i = 0; i < childDivs.length; i++)
{
childDivs[i].className = 'foo' + (i+1).toString();
}