+ 1
Change style of div
Is there any way to make the last line of the code below to random a background color for all the div created from the "for loop"? var x=Math.random()*3; var random=Math.floor(x); var list=new Array["red","blue","green"]; var bgcolor=list[random]; for(i=0;i<10;i++){ var ele=document.createElement("div")} ele.style.width="50px"; ele.style.height="50px" ele.style.background=bgcolor;
1 Respuesta