I have an external <script>
being added to the page via jQuery with:
$("body").append("<scr"+"ipt src='url_do_script.js'></scr"+"ipt>");
This script adds some elements to the page (some tags). The script works perfectly, but it is asynchronous when loading the page, ie the page loads normally without waiting for what the script will return. But I need to manipulate some tags returned by this .js
as soon as they are available .
The problem is that I did not find a way to tell when this script was fully loaded on the page with jQuery.
With pure JavaScript I can tell by adding the script via document.createElement
and appendChild
. Just make a .onload
:
var e = document.createElement("script");
e.src = "url_do_script.js";
document.body.appendChild(e);
e.onload = function(){
// o script foi totalmente carregado
}
How do I do something with .append
of jQuery? I've tried other forms like .get
, .load
and .ajax
but it does not work because of CORS (cross-origin resource sharing).
I tried to put a onload="funcao()"
into <script>
and it also did not work.
Any idea how to do this or is there another way to use jQuery without being .append
?