When I try to get the color in javascript by using:
Code:
document.getElementById("pagnr").style.color
it returns: rgb(95, 83, 71) instead of #5f5347
Can I change this and how do I do it then..
_j
Internet Explorer returns the HEX value of color.
While Mozilla Firefox returns the rgb() value of color.
So you need to check for either condition and convert as needed.
Example:
HTML Code:
<div id="pagnr" style="color:#5f5347;">123456</div><script>
function toRGBHex(num)
{
var decToHex="";
var prr = new Array();
var arr = new Array();
var numStr = new String();
numStr = num;
prr = numStr.split("(");
numStr = prr[1];
prr = numStr.split(")");
numStr = prr[0];
arr = numStr.split(",");
for(var i=0;i<3;i++)
{
var hexArray = new Array( "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
var code1 = Math.floor(arr[i] / 16);
var code2 = arr[i] - code1 * 16;
decToHex += hexArray[code1];
decToHex += hexArray[code2];
}
return (decToHex);
}
var c = document.getElementById("pagnr").style.color;
var CheckHEX = c.split("#");
if(CheckHEX[1]){c = CheckHEX[1];}
else{c = toRGBHex(c);}
alert("#" + c);
</script>