In the following function I have been trying to append gradClass
to apply gradient background to a div at runtime.
function applyGradient(upto) {
var gradStyle = "background: -webkit-linear-gradient(left, #ff1a00 20%,#ffffff 30%);"
+ "behavior: url(PIE-1.0.0/PIE.htc);"
+ "-pie-background: linear-gradient(#ff1a00 20%, #ffffff 30%);";
var newPercent = Math.floor(upto / end * 100);
gradStyle = gradStyle.replace(/20/gi, newPercent);
gradStyle = gradStyle.replace(/30/gi, "100");
gradClass = ".gradClass{" + gradStyle + "}";
//method 1
//jQuery('head').append($('<style>').text(gradClass));
//error: IE8 some known issue in jQuery library
//method 2
//var styleTag = document.createElement('style');
//styleTag.type = "text/css";
//styleTag.appendChild(document.createTextNode(gradClass));
//method 3
document.getElementsByTagName('style')[0].innerHTML += gradClass;
// Unknown runtime error in IE8.
jQuery("#container").addClass("gradClass");
}
Code works fine in Chrome but fails in IE8.
Having failed to apply the class using method 1
jQuery, I tried other two approaches as well.
What am I doing wrong ?