S
S
Shimpanze2018-02-10 03:16:53
JavaScript
Shimpanze, 2018-02-10 03:16:53

Can you explain why addEventListener is not working?

Hello!
I am copying information from one container to another and I need to track the moment when this process is completed completely.
I write like this:

// само копирование
document.getElementById('temp-content').innerHTML = document.getElementById('content').value;

// далее навешиваю обработчик который следит за контейнером
// и (теоретически) должен мне сообщить когда тот будет полностью готов
document.getElementById('temp-content').addEventListener("load", function() {
  alert('Весь HTML-контент загружен в контейнер!');
});

It is the event that is important to me load, since it allows you to track the complete loading of all resources (including images).
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-02-10
@Shimpanze

Because there is no such event.
HTML is inserted synchronously, no events are needed here.
To track the loading of images, after inserting, you need to select all the images in the desired element, and hang a handler on each.
At the same time, you need to take into account that some image may not load, and some may freeze in the loading state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question