While working on coding a website, I attempted to change colors and pictures onclick using JavaScript to edit the CSS. However, the code is only partially functional. Only the "txtArea" field changes color. After checking validators and consoles, everything seems to be syntactically correct.
<!-- This button triggers the color change. -->
<div id="colorSelector"><span id="chngBlue"><a href="#" onclick="chngColor()">•</a></span> • •</div>
<script>
var colors = ["#0099cc", "#669900", "#993333"];//Blue, Green, Red
function chngColor(){
document.getElementById("txtArea").style.backgroundColor = colors[2];
document.getElementsByClassName("labHdr")[0].style.backgroundColor = colors[2];
document.getElementById("newLink").style.color = colors[2];
document.getElementById("hdBanner").src='bannerred.png';
}
</script>