Skip to content

Instantly share code, notes, and snippets.

@jonathanhudak
Last active March 3, 2023 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanhudak/f4917f23434b8f8b6bf0e55c9c3333b2 to your computer and use it in GitHub Desktop.
Save jonathanhudak/f4917f23434b8f8b6bf0e55c9c3333b2 to your computer and use it in GitHub Desktop.
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