Skip to content

Instantly share code, notes, and snippets.

@Giagnus64
Created September 17, 2019 18:02
Show Gist options
  • Select an option

  • Save Giagnus64/e8fff81659485d815417909af2af61d1 to your computer and use it in GitHub Desktop.

Select an option

Save Giagnus64/e8fff81659485d815417909af2af61d1 to your computer and use it in GitHub Desktop.
Other Event Listener function
const colorBtnSim = document.querySelector(".simulate-color");
const divToChange = colorBtn.parentElement;
colorBtnSim.addEventListener('click', colorBtnSimClicked);
function colorBtnSimClicked(event){
const colors = ["skyblue", "green", "orange", "yellow"];
event.target.parentElement.style.backgroundColor = colors[Math.floor(Math.random()*colors.length)];
}
//original color button event listener
const colorBtn = document.querySelector(".color-button");
colorBtn.addEventListener('click', colorBtnClicked);
// original color button callback
function colorBtnClicked(event){
const colors = ["skyblue", "green", "orange", "yellow"];
event.target.parentElement.style.backgroundColor = colors[Math.floor(Math.random()*colors.length)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment