I have a div
that should make a append
of some elements and then do a scroll by the end of it.
The problem is that scroll runs before append is finalized. The (generic) code looks 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 can vary and will end up being longer than the time I set in setTimeout
and again will not execute second command.
What happens is that since the first command was not complete, the second command has no content to give scroll , as the commands follow without necessarily finishing.
What I need is some kind of verification that looks at whether append
has been finalized, or something, so the code can continue. And the function with these commands is only called once.