Pass the callback function as an argument to your function, and then call it after loading your stylesheet.
For instance:
function myFunc() { alert("Hello, World"); } loadStyleSheet("link/to/stylesheet.css", myFunc); function loadStyleSheet(url, callback){ if(document.createStyleSheet) { try {document.createStyleSheet(url);} catch (e) { } } else{ var css; css = document.createElement('link'); css.rel = 'stylesheet'; css.type = 'text/css'; css.media = "all"; css.href = url; document.getElementsByTagName("head")[0].appendChild(css); } callback(); }
EDIT
If you want to check if it loaded the stylesheet correctly, you will need to use AJAX .
source share