There are no errors thrown in the code, so I can only assume either the events aren't getting triggered or they aren't getting added properly. Can anyone determine what the issue is here?
Code below. Fiddle here.
$('#fake-body').append('init<br />');
var scriptTag,
scriptsLoaded = 0,
scripts = ['//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js', '//codeorigin.jquery.com/ui/1.9.2/jquery-ui.min.js'],
scriptLoadedCallback = function(val) {
scriptsLoaded++;
$('#fake-body').append('callback called for '+val+' | scriptsloaded = '+scriptsloaded+' & length = '+scripts.length+'<br />');
if(scriptsLoaded === scripts.length) {
$('#fake-body').append('all loaded');
}
};
$.each(scripts, function(index, value) {
$('#fake-body').append('preparing '+value+'<br />');
scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src = value;
if(typeof scriptTag.addEventListener !== 'undefined') {
$('#fake-body').append('add event for good browsers<br />');
scriptTag.addEventListener('load', (function() {
scriptLoadedCallback(value);
}), false);
} else {
$('#fake-body').append('add event for the other one<br />');
scriptTag.attachEvent('onreadystatechange', function() {
if(scriptTag.readyState === 'loaded') {
scriptLoadedCallback(value);
}
});
}
$('#fake-body').append('appending script<br />');
$('#fake-body').append(scriptTag);
});
$('#fake-body').append('complete');