The issue you're seeing is due to the fact that jQuery.load() works asynchronously.
Therefore, when you place the alert()
in between the two calls, you give a chance to the first call to complete, and then the second call works. Without that alert()
, the first load()
hasn't completed yet when the second load()
is called.
Use a callback function to fix:
$('section').load('welcome.html', function() {
$('#login').load('login.html');
});