JSFiddle - React, Tailwind, and code Playground
by Anand Rathod
HTML
<div style="background-color: #fff">test</div>
<div style="background-color: #121212">test</div>
JavaScript
function isDark( color ) {
var match = /rgb\((\d+).*?(\d+).*?(\d+)\)/.exec(color);
return ( match[1] & 255 )
+ ( match[2] & 255 )
+ ( match[3] & 255 )
< 3 * 256 / 2;
}
$('div').each(function() {console.log($(this).css("background-color"))
$(this).css("color", isDark($(this).css("background-color")) ? 'white' : 'black');
});