You can create boards of any size you want, and thus it is quite easy to resize squares and colors. you do not need to change anything.
It’s good practice to keep the appearance in the stylesheet. Also do not use document.write
http://jsfiddle.net/YEJ9A/1/
Javascript
var x=8; var y=8; var chessBoard = document.getElementById("chessBoard"); for (var i=0; i<y; i++){ var row = chessBoard.appendChild(document.createElement("div")); for (var j=0; j<x; j++){ row.appendChild(document.createElement("span")); } }
CSS
#chessBoard span{ display: inline-block; width: 32px; height: 32px; } #chessBoard div:nth-child(odd) span:nth-child(even), #chessBoard div:nth-child(even) span:nth-child(odd){ background-color: black; } #chessBoard div:nth-child(even) span:nth-child(even), #chessBoard div:nth-child(odd) span:nth-child(odd){ background-color: silver; }
source share