I do agree with gavgrif answer its one of the easiest way for static bgcolor ,Hence if user is going pick dynamic color as an background then its better to change text color according to
In below JS Fiddle on page load i am getting bg value of an background i.e rgb(220,110,140) taking its average and comparing with 127.5(average of i.e(255,255,255)) if its greater i am making text color has black else text color has white
https://jsfiddle.net/swaminathang/ezg47hag/2/
<div id="bgblock" >
<h1 id="textColor">
Hello world
</h1>
</div>
#bgblock{
width:400px;
height:200px;
background-color:#000000;
}
$( document ).ready(function() {
var bgColorString , hexvalue,hexvalue1,hexvalue2,hexvalue3
bgColorString = $("#bgblock").css('backgroundColor').toString();
hexvalue = bgColorString.split("(")[1].split(")")[0]
hexvalue1 = parseInt(hexvalue.split(",")[0]) ;
hexvalue2 = parseInt(hexvalue.split(",")[1]) ;
hexvalue3 = parseInt(hexvalue.split(",")[2]) ;
var coloravg = (hexvalue1 + hexvalue2+hexvalue3)/3;
if(coloravg > 127.5){
$("#textColor").css("color","black");
}else{
$("#textColor").css("color","white");
}
});