Skip to content

Instantly share code, notes, and snippets.



Created Sep 13, 2013
What would you like to do?
Cross-browser CSS-loaded detector, without browser sniffing.
#targ {
position: absolute;
<!DOCTYPE html>
<meta charset="utf-8" />
<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"); = "100px";
}, 1000);
<div id="targ">left?</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment