Skip to content

Instantly share code, notes, and snippets.

@Ankhena
Last active September 25, 2021 09:49
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 Ankhena/dc68e4b63011f76d10bb68a3667fd9b6 to your computer and use it in GitHub Desktop.
Save Ankhena/dc68e4b63011f76d10bb68a3667fd9b6 to your computer and use it in GitHub Desktop.
Colors the selected elements in random colors. Launch: colorBlocks ('. random');
const colorBlocks = (block) => {
const items = document.querySelectorAll(block);
items.forEach(item => {
let color = (Math.random().toString(16) + '000000').substring(2, 8).toUpperCase();
item.style.setProperty('--bg-color', '#' + color);
})
}
colorBlocks('.random');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment