Source Code:
(back to article)
Submit
Result:
Report an issue
<div> <button id="colorButton">Click me to change color</button> </div> <script> document.getElementById('colorButton').addEventListener('click', function() { this.style.backgroundColor = this.style.backgroundColor === 'red' ? 'blue' : 'red'; }); </script>