I have a string in javascript that I want to use to instantiate a child element for a particular element, eg:
let target = document.getElementById("target")
let string = ```
<div>
<img src="somewhere">
<h1> This is a heading </h1>
<p> And some text <p>
</div>
```
target.innerHTML = string
Later, I want to find the offset of the heading:
// ...
// later
// ...
let heading = target.getElementByTagName("h1")
console.log(heading.offsetTop)
But sometimes its incorrect because sometimes the image (or any other external element) has loaded, and sometimes it hasn't loaded before I find the offset. Can anybody suggest a jquery free way to determine when the contents of target
have finished loading all external resources?