Edit: It may not all be to do with the length of the color value as you guys are saying. Because even if I add this line it still doesn't change the background on Safari like it should:
newEle.style.background = "-webkit-gradient(linear, left top, right top, from(#2F2727), to(#FF0000))";
I am dynamically setting a HTML p elements background color.
My Problem: When I go to store a string(Returned from my function) in ele.style.backgroundColor it doesn't stay or change the background color. I am unsure why my function cannot change the background color of this element to black?
<html>
<head>
</head>
<body>
<div id="mainContent">
<p id="test">abcdef</p>
</div>
</body>
<script type="text/javascript">
<!--
function decimalToHex( num )
{
// num is usually a decimal color in form ARGB
if (num == null || num == "undefined") { return "#FFFFFF"; }
var intNum = (parseInt(num,10)) & 0x00FFFFFF;
return "#"+intNum.toString(16);
}
var newEle = document.createElement("p");
newEle.style.backgroundColor = decimalToHex(0); // this fails doesn't set the background color
//newEle.style.backgroundColor = "#FF0000"; // But this works & sets it to red. Whats wrong with my function?!
newEle.innerHTML = "kjdskjdkgj";
document.getElementById("mainContent").appendChild(newEle);
-->
</script>
</html>