Hi I'm starting to learn javascript and I have a button that when I click, it changes the header, nav bar, footer, and some text from one colour to another and when I click it again, it reverts back to it. There is a proper html/css files that go with it but I'm not sure if this is the correct approach.
Is there some way to maybe work with the id so that I can change the CSS instead?
This is my current approach with my script.:
<script>
function changeColor() {
var color = 0;
if (color == 0) {
document.getElementById("topBar").style.background = "#36648B"
document.getElementById("topBar").style.color = "#C1F0F6"
document.getElementById("myBlog").style.background = "#62B1F6"
document.getElementById("navBar").style.background = "#9BC4E2"
document.getElementById("footer").style.background = "#50A6C2"
var y = document.getElementsByClassName("sideCol")
y[0].style.background = "#C3E4ED"
}
}
</script>
.color1&.color2. Then using JS change add/remove the appropriate class.