First: 1, 2, 3, are not valid class names. See here.
a name must begin with an underscore (_), a dash (-), or a letter(a–z), followed by any number of dashes, underscores, letters, or numbers.  
Second: 'class' is a future reserved word. Use className instead. 
Here is an example using pure javascript and legal css names: jsfiddle
css:
.foo1
{
    color:blue;    
}
.foo2
{
    color:red;    
}
Html:
<div id="main">
  <div>1</div>
  <div>2</div>
</div>
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();
}