How to change button color onclick using javascript only?
问题 I was trying to make the color of the buttons change using onclick and getElementsByClassName and came up with something like this: HTML: <button onclick="submitButtonStyle()" type="submit" class="stylebutton"> Submit </button> JS: function submitButtonStyle() { document.getElementsByClassName("stylebutton").style.backgroundColor = "red"; } I would be really grateful if you guys gave me a hint about what is lacking in my code/what I should add etc. 回答1: getElementsByClassName returns an