I making a game with few scenes. Each scene have it's own javascript which i want to load asynchronously and after that to load the particular scene file into div.
Here is my html index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.js"> </script>
<script type="text/javascript" src="first.js" id="first" ></script>
</head>
<body>
<div id="test" style="width: 800px; height: 400px; background: black">
hello
</div>
<button id="submit">submit</button>
</body>
</html>
Here is two working functions.
First one
$(document).ready(function() {
$('#submit').click(function() {
(function() {
var myscript = document.createElement('script');
myscript.type = 'text/javascript';
myscript.src = ('second.js');
var s = document.getElementById('first');
s.parentNode.insertBefore(myscript, s);
})();
});
});
And here is the second
$( "#test" ).load('div.html');
I want the second command: $( "#test" ).load('div.html'); to be executed straight after the scripts loading finished successfully.
How can i do that?