views:

27

answers:

1

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);
}
A: 

@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);
}
Nick
also var boolyStyle; is set outside the function
Nick