cross browser function to dynamically load an external css file. see: github page
Download the file jquery.getCSS.js and include it in the header of your html:
<script src="jquery.getCSS.js"></script>
if jQuery is loaded it adds the getCSS function to the jQuery object:
$.getCSS("getCSS.css");
Otherwise it adds it to the window object:
window.getCSS("getCSS.css");
the function takes an attributes hash or a string
// file name as string:
$.getCSS("fresh.css")
// attributes as hash:
$.getCSS({href:"cool.css", media:"print"})
$.getCSS({href:"/styles/forest.css", media:"screen"})
Tested with Firefox, Chrome, IE
Open this link: Test Page and click applyCSS and the external css file should be loaded and the styles should be applied.
Original Idea by: Soviut http://stackoverflow.com/questions/1184950/dynamically-loading-css-stylesheet-doesnt-work-on-ie
IE special: http://msdn.microsoft.com/en-us/library/ie/ms531194(v=vs.85).aspx
Having trouble with this script? Please let me know: [email protected].