I've got a button that when pressed changes a variable between true and false. When true I want the test to display blue, when false I want the text to display black. I'm not sure why but the text is staying blue, despite the variable changing. Here's my code:
<div id="test1">Hello</div>
<button onclick="change()">Change</button>
<script>
var swap = true;
function change(){
if(swap === true){
swap = false;
}
else{
swap = true;
}
document.getElementById('test1').innerHTML = swap;
}
if(swap === true){
document.getElementById("test1").style.color = "blue";
}
else if(swap === false){
document.getElementById("test1").style.color = "black";
}
</script>