Posted By

mrb23771 on 11/13/15


Tagged


Versions (?)

loadCSS (function)


 / Published in: jQuery
 

Load a css file in to the document, check if allready loaded, if not, load css

  1. function loadcss (cssFile){
  2. var found = false;
  3. for(var i = 0; i < document.styleSheets.length; i++){
  4. if(document.styleSheets[i].href===cssFile){
  5. found=true;
  6. break;
  7. }
  8. }
  9. if (!found){
  10. if (document.createStyleSheet){
  11. document.createStyleSheet(cssFile);
  12. }
  13. else {
  14. var html = $.parseHTML ('<link href="' + cssFile + '" rel="stylesheet" type="text/css">');
  15. $("head").append(html);
  16. }
  17. }//if(!found)
  18. }

Report this snippet  

You need to login to post a comment.