开发者

Issue editing class style properties using js - issue is with IE

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 + '}' +
        '.mer开发者_如何学运维ch_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);
}


@Pointy - I didn't really need the top part

 function myRemoveElement(id)   {
    var Node = document.getElementById(id);
    Node.parentNode.removeChild(Node);
}

function boolyChangeFoo(width1, width2, width3, width4) {
        var append = true;
        myStyle = document.createElement('style');
    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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜