Dynamic Load scripts right order !

by Ben Clayton

HTML

<button id="add">
  addthem
</button>

<div id="here">

</div>
<br/>
This load a js library some css then a small test script which runs a method from the js library. As the test script is small it loads fastest and runs before the library is loaded, giving an error. The 1000ms delay is a cludge to make it work, Needs a proper syncronous loading order.

JavaScript

$("#add").click(function() {

  $("#here").append("<sc" + "ript src='https://flowcms.infxsolutions.com/script/sweet-alert/sweet-alert.js'></sc" + "ript>");
  $("#here").append("<link href='https://flowcms.infxsolutions.com/script/sweet-alert/sweet-alert.css' rel='stylesheet' media='all'>");

  setTimeout(function() {
    $("#here").append("<sc" + "ript src='https://flowcms-bc.infxsolutions.com/test.js'></sc" + "ript>")
  }, 1000);


})