How To Check If The Css Background-color Is White?
I need this: $('*').each(function() { if($(this).css('background-color') == '#ffffff') { $(this).css('background-color') == '#000000' } });�
Solution 1:
Even if it were correct (it's not), it would be unreliable and unlikely to work. The reason for that is that there are several ways of showing a white colour:
white
#ffffff
and all 64 case combinations thereof#fff
and all 8 case combinations thereofrgb(255,255,255)
and all ∞ combinations of arbitrary whitespace between valuesrgba(255,255,255,1)
and all ∞ combinations of arbitrary whitespace between values
You could check it this way:
if( $(this).css("background-color").match(/^(?:white|#fff(?:fff)?|rgba?\(\s*255\s*,\s*255\s*,\s*255\s*(?:,\s*1\s*)?\))$/i))
this.style.backgroundColor = "#000";
Post a Comment for "How To Check If The Css Background-color Is White?"