Skip to content

Instantly share code, notes, and snippets.

@marrisonlab
Last active December 18, 2025 13:49
Show Gist options
  • Select an option

  • Save marrisonlab/1ef655c170a12c6e04595167286a49f5 to your computer and use it in GitHub Desktop.

Select an option

Save marrisonlab/1ef655c170a12c6e04595167286a49f5 to your computer and use it in GitHub Desktop.
random color
<script>
// 1. Seleziona tutti gli elementi con la classe 'bg-change'
const elements = document.querySelectorAll(".bg-change");
// 2. Itera su ogni elemento trovato
elements.forEach(element => {
// 3. GENERA UN NUOVO COLORE CASUALE AD OGNI ITERAZIONE del ciclo
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
// 4. Applica il nuovo colore all'elemento corrente
element.style.backgroundColor = randomColor;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment