I’m doing the following:
First, inject HTML into the page (a lot) which then increases the window scrollbar:
$("#XXXX").html("LOTS OF HTML").show();
Then i want to scroll down to the end of the page:
window.scrollTo(0,$(document).height());
Problem is the page never scrolls down. I did some console.logging and the scrollTo is running before the HTML from the inject html() is run. I tried this in the JS which injects the HTML, I then tried doing the scroll inside the HTML inject but that made no difference.
Any ideas?
Here’s something to try:
$.ajax({ //other params //params success: function(data) { $("#XXXX").html(data).show(); } complete: function() { window.scrollTo(0,$(document).height()); } });The success function runs when the call is successful, and the complete function runs after that, so it might work!
Here’s the jQuery docs on .ajax()