0

I want to load an external JS file on a page after wherever jQuery is loaded.

The solution below doesn't seem to work that way as I don't just want to load an external file rather after wherever jquery < script src="js/jquery-3.6.0.min.js"> is loaded:

$("main").append($("<script></script>").attr("src", url));

Any thoughts are highly appreciated.

Asif Raza
  • 35
  • 5
  • javascript is evaluated from top to bottom, so it should be enough to use the – Diego D May 02 '22 at 11:15
  • or you could follow the answer here that perfectly fits your exact scenario: https://stackoverflow.com/questions/14521108/dynamically-load-js-inside-js – Diego D May 02 '22 at 11:16
  • you are probably aiming at the wrong solution to address a problem you are having that you didn't state in your question. Something like trying to attach an event handler to a dom element without the page being loaded yet. – Diego D May 02 '22 at 11:19
  • @DiegoDeVita - think you are right. I only want an external file/script loaded after jquery or appended after jquery is loaded. Not sure which would make sense but that's what I need to do. – Asif Raza May 02 '22 at 11:23
  • just have the script tag for your JS file after the script tag of jquery? – Sudhir May 02 '22 at 11:32
  • @AsifRaza then you have your solution and I don't know why you are still trying to explicitely load a js after jQuery. You've already got your answer if you have nothing else to add to the question. jQuery will be loaded before anything else if it appears as the first – Diego D May 02 '22 at 11:43

0 Answers0