Skip to content

Instantly share code, notes, and snippets.

@jonathanhudak
Last active March 3, 2023 07:00
Embed
What would you like to do?
const div = document.createElement("div");
div.style.padding = "2rem";
div.style.display = "flex";
div.style.justifyContent = "space-between";
div.style.maxWidth = "700px";
const button = document.createElement("button");
const colors = ["indigo", "purple", "gold", "khaki", "aqua"];
function getRandomColor() {
return colors[Math.floor(Math.random()*colors.length)];
}
button.innerText = "do something";
button.addEventListener("click", () => {
div.style.backgroundColor = getRandomColor();
});
div.appendChild(button);
document.body.appendChild(div);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment