A Pen by Fahad Murtaza on CodePen.
Created
January 26, 2023 03:16
-
-
Save fahdi/aeae17b5ad51d2bcb186386fc25766f9 to your computer and use it in GitHub Desktop.
BG Changer JS events example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button onclick="changeColor()">Repaint!</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandomColor() { | |
let letters = "0123456789ABCDEF"; | |
let color = "#"; | |
for (let i = 0; i < 6; i++) { | |
color += letters[Math.floor(Math.random() * 16)]; | |
} | |
return color; | |
} | |
function changeColor() { | |
let newColor = getRandomColor(); | |
document.body.style.backgroundColor = newColor; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
button { | |
display: block; | |
margin-left: auto; | |
margin-right: auto; | |
width: 25%; | |
margin-top: 10%; | |
font-size: 16px; | |
padding: 5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment