how to replace entire css text with another?


Tags: javascript,jquery,css,coding-style,stylesheet

Problem :

I have web page with different styles that the user can change and build on the fly. I have this code working with browsers IE-9+,chrome,FF,safari.

if($("#customCss").length>0)
     $("#customCss").empty();

$("#customCss").text(css_txt );
$('head').append('<style type="text/css" id="customCss"> ' + css_txt + '</style>');

I want to fit the site to IE-7,8. But this code not working with IE-7,8. I am getting this error code:

Microsoft JScript runtime error: Unexpected call to method or property access.

in this jquery func jquery :

append: function () {
            return this.domManip(arguments, true, function (elem) {
                if (this.nodeType === 1) {
                    this.appendChild(elem);
                }
            });
        },

I have try this also with no luck :

document.getElementById("customCss").innerHTML=css_txt;

any idea why?



Solution :

Store a reference to the link tag and then modify the href to the new script if it's an external script. If it's internal, try removing the old one with .remove() and .append() a new one right after the <body>.


    CSS Howto..

    How to enable HTML content on top of Flash content without the frame rate dropping?

    how to make tab bar in jquery mobile?

    How to make div block fixed as window size changes?

    How can I delete these arrows?

    How to change qunit theme / layout

    How can I conditionally change css styles with js?

    How can I get a very “blurred” box-shadow out of only the bottom of the box?

    How to split css shape in half vertically?

    How do you tell a browser, “if you need to wrap, wrap here first”?

    How to center the boxes as shown?

    Apple's Website - How Does It Autosize Itself For Mobile Devices?

    How can I force LESS (css) to recognize a variable?

    How to setup CSS for multiple font choices? [closed]

    How do I make link the highlight link conform to CSS shape

    How is “:after” element's height and width determined? [closed]

    How to use jQuery to read/write the values of an elements externally defined css class?

    How to add a second slideshow on the same webpage

    How to use custom css file for layout of a module in Yii2

    How to prevent fixed button from overlapping footer area and stop the button on top of where the footer is located

    How to make div 10% of device screen height css

    how to give space between tr tag and divide by | in html

    How to hover over the whole button in css

    How can I separate areas with floats from each other?

    How is struts finding css files?

    how to add empty space between cells in tables?

    How to auto adjust (stretch) div height and width using jQuery or CSS

    CSS dropdown submenu with dynamic width: how to align left?

    How to fix width of tooltip at IE8

    How can I keep the hovered menu item open so I can edit it's style with firebug?

    How to make `margin: top;` based on browser height?