SlowCoder
01-14-2012, 03:36 AM
I'm a true newbie when it comes to JavaScript. To learn the language, I've set up a project for myself, a sort of board game.
As it is, I have a series of divs, each with an image (img tag). The divs ids are "Space1", "Space2", "Space3", etc. I am trying to dynamically create child divs inside the space divs as player markers. Here is the code:
<script type="text/javascript">
for(intA=0;intA<=10;intA++){
var NewDiv=document.createElement("div")
NewDiv.setAttribute("id","Space"+intA+"Player1")
NewDiv.style.width="20px";NewDiv.style.height="20px"
NewDiv.style.position="relative"
NewDiv.style.left="10px";NewDiv.style.top="10px"
NewDiv.innerHTML="1"
NewDiv.style.backgroundColor="#333333"
NewDiv.style.border="2px solid black"
NewDiv.style.visibility="visible"
NewDiv.style.zIndex="1000"
document.getElementById("Space"+intA).appendChild(NewDiv)
}
</script>
The assumption is that this code should make a 20x20 gray box with a "1" in it. I've tried playing with the visibility and the z-index, but nothing is showing up. What am I doing wrong here?
As it is, I have a series of divs, each with an image (img tag). The divs ids are "Space1", "Space2", "Space3", etc. I am trying to dynamically create child divs inside the space divs as player markers. Here is the code:
<script type="text/javascript">
for(intA=0;intA<=10;intA++){
var NewDiv=document.createElement("div")
NewDiv.setAttribute("id","Space"+intA+"Player1")
NewDiv.style.width="20px";NewDiv.style.height="20px"
NewDiv.style.position="relative"
NewDiv.style.left="10px";NewDiv.style.top="10px"
NewDiv.innerHTML="1"
NewDiv.style.backgroundColor="#333333"
NewDiv.style.border="2px solid black"
NewDiv.style.visibility="visible"
NewDiv.style.zIndex="1000"
document.getElementById("Space"+intA).appendChild(NewDiv)
}
</script>
The assumption is that this code should make a 20x20 gray box with a "1" in it. I've tried playing with the visibility and the z-index, but nothing is showing up. What am I doing wrong here?