2
I have a div
that should make a append
of some elements and, after that, should make a scroll until the end of it.
The problem is that the scroll is executed before the append is finished. The (generic) code is like this:
$("div").append(output);
$("div").prop("scrollTop", $("div").prop("scrollHeight"));
If I put the second command inside a setTimeout
, this all works, but sometimes the append time may vary and end up being longer than the time I set in setTimeout
and again will not execute the second command.
What happens is that since the first command was not complete, the second has no content to give scroll, because the commands follow, without necessarily having finished.
What I need is some kind of verification that observes whether the append
was finished, or something, so the code can continue. And the function with these commands is only called once.
Unfortunately this mode did not work. In fact, I had already tried, without success.
– Marlon
@Marlonluís if you have how to post more details, the div and the content of the append, can be in jsfiddle.net, we go after the solution.
– Mathiasfc
All right, @Mathias, I managed to solve the problem and posted the result below.
– Marlon
@Marlonluís Maravilha, I’m glad you were able to answer, I hope my answer will be more useful next time, I even considered suggesting the setInterval but I found it a little dangerous, anyway good that it worked.
– Mathiasfc