Cross-browser CSS-loaded detector, without browser sniffing.
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<script type="text/javascript"> | |
function loadCSS(src, cb) { | |
var head = document.getElementsByTagName('head')[0]; | |
var link = document.createElement('link'); | |
link.setAttribute('href', src); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute('charset', 'utf-8'); | |
head.insertBefore(link, head.firstChild); | |
(function check() { | |
if(link[document.createStyleSheet ? 'styleSheet' : 'sheet']) { | |
return cb && cb(link); | |
} | |
setTimeout(check, 0); | |
})(); | |
} | |
setTimeout(function() { | |
loadCSS('style.css', function(link) { | |
var el = document.getElementById("targ"); | |
el.style.left = "100px"; | |
}); | |
}, 1000); | |
</script> | |
</head> | |
<body> | |
<div id="targ">left?</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment