I've got a problem with some Javascript-generated content :
I use the onload()
event of my html page to load HTML code from a server and inject it in the page. Since it already is html I use the innerHtml
property of the nodes I want to fill with content.
Once I've injected the HTML I call a handmade adjustHeights()
function that normalizes the height of the elements I created this way to make them all match the height of the tallest element.
All of this works perfectly unless the code inside innerHtml
contains some sort of image or other media that takes time to load (particularly videos) because adjustHeights()
is called between the injection of the code and the end of the loading time of the image/video/etc.
Is there any way to wait for every element to be loaded before calling adjustHeights()
? I've already tried the document.onreadystatechange
property but the state is already on 'completed' when I start to inject code.
If it's possible I would rather not use time-based calls on adjustHeights()
.
To make it clearer here's an example :
var mylist = document.getElementById('mycontent');
var li;
for (var i = 0; i < res.length; i++)
{
li = document.create('li');
li.innerHTML=res[i];
mylist.appendChild(li);
}
adjustHeights();