Skip to content

Instantly share code, notes, and snippets.

Created Nov 3, 2014
What would you like to do?
var list = document.getElementById("box").getElementsByTagName("span"), bgUsed={};
for (var i = 0, len = list.length; i < len; i++) {
var e = list[i].style.backgroundColor;
if(Object.keys(bgUsed).length==0){bgUsed[e]=i; continue;}
if(!bgUsed.hasOwnProperty(e)) {bgUsed[e]=i; continue; }
else if(Object.keys(bgUsed).length > 1) { delete bgUsed[e]; break;}
list[bgUsed[Object.keys(bgUsed)[0]]].style.backgroundColor="black"; // bg en black
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment