How to tell javascript to execute a function after loading an element through an external library?Usually I have to bring a tag <script>after the element itself to work with DOM calls.
<script>
Well, you can use methods document.onloadand window.onload For example:
document.onload
window.onload
window.onload = function(){ //do some stuff }
If you do not want to wait for the page to fully load, you can also poll the existence of the element:
function myFunc() { if (document.getElementById('myElement')) { // do stuff } else { setTimeout(myFunc, 15); } }
script body . , onload. onload .