Q:

How do you change button color when it is clicked?

Im doing a school project where I'm coding a website for extra credit, so I'm trying to make it look as fancy as possible.
My main goal right now is to let a button change color when its clicked, like how it shows which page is selected on the multi-page website. Please someone help quick, it's due in a week and I got a LOT of fancying to do.
Oh yeah, it's on a learners website (-_-) so right now I'm limited to types of code I can use.
Thanks please help me quickly.

A:

this is my simple way of doing it for beginners and that's how I started out and learning. Also my CodePen is here if you want to try it and see it working: CodePen for Changing Colors onclick

function changeColor(){
document.getElementsByClassName("myButton")[0].style.backgroundColor = "red";
}
<button class="myButton" style="background-color:blue;" onclick="changeColor()">Change Color</button>

