Issue editing class style properties using js - issue is with IE
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-05-23T19:49:59Z
Indexed on
2010/05/23
20:31 UTC
Read the original article
Hit count: 347
JavaScript
|internet-explorer
I have a function to edit the style properties of a class
Unfortunately IE does not seem to like it but it does not give me an error.
Does anyone know what the issue is?
Thanks in advance
function myRemoveElement(id) {
var Node = document.getElementById(id);
Node.parentNode.removeChild(Node);
}
function boolyChangeFoo(width1, width2, width3, width4) {
if(typeof style == 'undefined') {
var append = true;
myStyle = document.createElement('style');
} else {
while (myStyle.hasChildNodes()) {
myStyle.removeChild(myStyle.firstChild);
}
}
if (document.getElementById('my_custom_styles'))
{
myRemoveElement('my_custom_styles');
}
var head = document.getElementById('myltd_popup_1');
var rules = document.createTextNode('.my_price_comp_inner { width: ' + width1 + '}' +
'.merch_coupons_summary { width: ' + width2 + '}' +
'.merch_coupons_data { width: ' + width3 + '}' +
'.my_coupon_prod_item { width: ' + width4 + '}'
);
myStyle.setAttribute('type','text/css');
myStyle.setAttribute('id', 'my_custom_styles');
if(myStyle.styleSheet) {
myStyle.styleSheet.cssText = rules.nodeValue;
} else {
myStyle.appendChild(rules);
}
//alert(myStyle);
if(append === true) head.appendChild(myStyle);
}
© Stack Overflow or respective owner