I was playing with javascript and decided to make a theme changer, unfortunately when one clicks on a button to change the theme, nothing happens. I'm using an old browser that doesn't support "alert()" but I've been able to test and change theme elements before. Here is the code I made:
Code:
If anyone would be willing to see why this isn't working and tell me why, I'd be a happy camper.
Code:
<body id="body" style="background-color:black; color:white;">
<p id="themeChoice"></p>
<h4>Change Theme</h4>
<button style="background-color:black; color:white;" onclick="theme(1);return false;">White on Black</button>
<button style="background-color:white; color:black;" onclick="theme(2);return false;">Black on White</button>
<button style="background-color:blue; color:yellow;" onclick="theme(3);return false;">Yellow on Blue</button>
</body>
<script>
function theme(tc) {
document.getElementById('themeChoice').innerHTML=tc; //Debug purposes.
if (tc == 1) {
body.style.background-color='black';
body.sytle.color='white';
} else if (tc == 2) {
body.style.background-color='white';
body.style.color='black';
} else if (tc == 3) {
body.style.background-color='blue';
body.style.color='yellow';
} else {
output.innerHTML='Error: Invalid Theme!';
output.style.background-color='red';
output.style.color='white';
}
}
</script>
If anyone would be willing to see why this isn't working and tell me why, I'd be a happy camper.