title: link element onload
body: <p>Is there anyway to listen to the onload event for a <code>&lt;link&gt;</code> element?</p>
  
  <p>F.ex:</p>
  
  <pre><code>var link = document.createElement('link');
  link.rel = 'stylesheet';
  link.href = 'styles.css';
  
  link.onload = link.onreadystatechange = function(e) {
      console.log(e);
  };
  </code></pre>
  
  <p>This works for <code>&lt;script&gt;</code> elements, but not <code>&lt;link&gt;</code>. Is there another way?
  I just need to know when the styles in the external stylesheet has applied to the DOM.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Would it be an idea to inject a hidden <code>&lt;iframe&gt;</code>, add the <code>&lt;link&gt;</code> to the head and listen for the <code>window.onload</code> event in the iframe? It should trigger when the css is loaded, but it might not guarantee that it's loaded in the top window...</p>