Shoora
6/17/2013 - 11:26 AM

loadcss.js

loadcss.js

(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'));