Change the background color of a <button> element:
Click the button to change its background color.
<!DOCTYPE html> <html> <body> <button id="myBtn">Test</button> <script> document.getElementById("myBtn").addEventListener("click", function(){ this.style.backgroundColor = "red"; });/*from w ww.ja va 2s. c om*/ </script> </body> </html>