I am trying to check for the background of an element, here is my code. But it doesn\'t work:
I tried two ways, here is the first:
function changeCol
I'm not sure what field is referring to, but my guess stands that it is the id of the element?
If so, try wrapping field like so $('#' + field).css.
NOTE: Here's a VERY NICE function for converting HEX to RGB
function hexToRgb(string)
{
if(!string || typeof string !== 'string') return false;
if(
string.substring(0,1) == '#' &&
(string.length == 4 || string.length == 7) &&
/^[0-9a-fA-F]+$/.test(string.substring(1, string.length))
){
string = string.substring(1, string.length);
if(string.length == 3)
string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2];
return 'rgb(' +
parseInt(string[0] + string[1], 16).toString() + ',' +
parseInt(string[2] + string[3], 16).toString() + ',' +
parseInt(string[4] + string[5], 16).toString() +
')';
}
else return false;
}