dwarfdude77
In Runtime
- Messages
- 270
- Location
- USA
Google is your friend (as is StackOverflow when you're programming):
javascript - CreateElement with id? - Stack Overflow
Several options there. You already have the instance object of redbtn tho when you created it...so you can also just do "redbtn.className=" and set the class there as well.
Okay, I have tried the redbtn.className="", and then set the class property "text-align:center;" in the css. Here is the code:
Javascript:
Code:
function change() {
var p= document.getElementById("main");
switch(p.innerHTML) {
case "Lines of Story <br> Presented by Cameron Palmer":
p.innerHTML="This is a text-based game.";
break;
case "This is a text-based game.":
p.innerHTML="It will be very boring.";
break;
case "It will be very boring.":
p.innerHTML="It's made for old people and nerds.";
break;
case "It's made for old people and nerds.":
p.innerHTML="Ahh... text based games.";
break;
case "Ahh... text based games.":
p.innerHTML="Chapter 1<br>Which color do you like more?";
var redbtn = document.createElement("BUTTON");
var redtext = document.createTextNode("Red");
redbtn.appendChild(redtext);
document.body.appendChild(redbtn);
redbtn.style.color="red";
redbtn.className="redbtn";
break;
}
}
CSS:
Code:
.redbtn{text-align: center;}