Skip to content

Instantly share code, notes, and snippets.

@seanmtracey
Last active December 22, 2015 21:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmtracey/6536865 to your computer and use it in GitHub Desktop.
Save seanmtracey/6536865 to your computer and use it in GitHub Desktop.
Random color generation for all DOM elements so you can see where that pesky whitespace is coming from.
m=Math.random,v=255;Array.from(document.querySelectorAll("*")).forEach(e=>{e.style.background=`rgb(${m()*v|0},${m()*v|0},${m()*v|0})`})
a=document.querySelectorAll('*'),m=Math.random,v=255,x=0;while(x<a.length){r=m()*v|0,g=m()*v|0,b=m()*v|0;a[x].style.background="rgb("+r+","+g+","+b+")";x++;}
var all = document.querySelectorAll('*');
for(var x = 0; x < all.length; x += 1){
var thisThing = all[x];
var r = Math.floor(Math.random()*255);
var g = Math.floor(Math.random()*255);
var b = Math.floor(Math.random()*255);
thisThing.style.backgroundColor = "rgba(" + r + ", " + g + ", " + b + ", 1)";
}
m=Math.random,v=255;Array.from(document.querySelectorAll("*")).forEach(e=>{e['style'].background=`rgb(${m()*v|0},${m()*v|0},${m()*v|0})`})
@JakeChampion
Copy link

m=Math.random,v=255;Array.from(document.querySelectorAll('*')).map(e=>e.style.background=rgb(${m()*v|0},${m()*v|0},${m()*v|0}))

@ralphsaunders
Copy link

Slightly more condensed ES6 version.

m=Math.random,v=255;for(e of Array.from(document.querySelectorAll('*'))){e.style.background=`rgb(${m()*v|0},${m()*v|0},${m()*v|0})`}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment