Skip to content
/ getCSS Public
forked from intesso/jquery-getCSS

Cross browser function for dynamic loading of external CSS files.

License

Notifications You must be signed in to change notification settings

mjun/getCSS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getCSS

Cross browser function for dynamic loading of external CSS files.

This is a fork of jquery-getCSS plugin by intesso with optional additional parameter "append" which controls if dynamically loaded CSS should be appended or replaced.

see: github page

Usage

Download the file getCSS.js or the minified version (only 574 bytes!) getCSS.min.js and include it in the header of your html:

	<script src="getCSS.js"></script>
	<script src="getCSS.min.js"></script>

This plugin does not depend on jQuery, but 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");

Options

The function takes two arguments, 'attributes' and 'append' of which the latter is optional. Argument 'attributes' can be passed as a string, indicating a path to the CSS file, or a map which defines all CSS reference attributes. If your statically loaded CSS in html has 'id' attribute defined, you can even replace that CSS if you supply 'id' key in attributes map.

	// attributes as string (path to 'fresh.css' file), appended to html:
	$.getCSS("fresh.css", true)

	// css defined via map, not appended:
	$.getCSS({href:"cool.css", media:"print"})
	$.getCSS({href:"/styles/forest.css", media:"screen"})
	
	// replaces statically defined css with id 'staticCSS'
	$.getCSS({href:"/styles/dynamic.css", media:"screen", id:"staticCSS"})

Testing

Tested with Firefox, Chrome, IE

Demo with jQuery Demo without jQuery

Credits

Original Idea by: Soviut http://stackoverflow.com/questions/1184950/dynamically-loading-css-stylesheet-doesnt-work-on-ie

Original plugin by: Intesso http://intesso.github.com/jquery-getCSS/

References

IE special: http://msdn.microsoft.com/en-us/library/ie/ms531194(v=vs.85).aspx

License

MIT License

Support or Contact

If you have any questions or problems with this script feel free to contact me at: [email protected]

About

Cross browser function for dynamic loading of external CSS files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.8%
  • CSS 3.2%