Skip to content

Instantly share code, notes, and snippets.

@fundon
Created December 15, 2011 08:29
Show Gist options
  • Save fundon/1480368 to your computer and use it in GitHub Desktop.
Save fundon/1480368 to your computer and use it in GitHub Desktop.
load css
(function(doc, type) {
var head = doc.getElementsByTagName('head')[0],
frag = doc.createDocumentFragment(),
add = function(url, id) {
if (doc.getElementById(id)) {return;}
var node = doc.createElement(type);
node.href = url;
id && (node.id = id);
//node.rel = 'stylesheet';
//node.type = 'text/css'
node.setAttribute('rel', 'stylesheet');
node.setAttribute('type', 'text/css');
// firefox chrmoe opera
frag.appendChild(node);
head.appendChild(frag);
// ie
//head.appendChild(node);
};
add('/css/test.css','abc');
}(document, 'link'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment