controlling css with javascript works with Mozilla & Chrome however not with IE

前端 未结 5 1370
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 17:57

Im having problems with this function applying css(using a text variable) working with Internet Explorer but it works in Firefox & Chrome.

the code:



        
5条回答
  •  孤独总比滥情好
    2021-01-05 18:27

    var style = document.createElement('style');
    

    Adding new stylesheets and scripts by creating elements using DOM methods is something that has always been dicey cross-browser. This won't work in IE or WebKit.

    style.rel = 'stylesheet';
    style.href = 'FireFox.css';
    

    There's no such properties on an HTMLStyleElement.