javascript: capturing load event on LINK

i’m trying to attach an event handler to the load event of a link tag, to execute some code after a stylesheet has loaded.

new_element = document.createElement('link');
new_element.type = 'text/css';
new_element.rel = 'stylesheet';
new_element.href = 'http://domain.tld/file.css';
new_element.addEventListener('load', function() { alert('foo'); }, false);

i have tried onreadystatechange as well

new_element.onreadystatechange = function() { alert('foo'); }

unfortunately neither approach results in an alert being triggered..
Furthermore, new_element.onload is null after registering a handler for the ‘load’ event with addEventListener.. is that normal?


ps: i may not use any framework in solving this

31 thoughts on “javascript: capturing load event on LINK”

  1. 396685 482205you are in point of fact a great webmaster. The internet site loading velocity is incredible. It seems that youre performing any distinctive trick. In addition, The contents are masterpiece. youve done a fantastic activity on this subject! 258432


Leave a Comment