The title explains my problem. So here's my code:
$("#my-div ul").scrollTop($("#my-div ul")[0].scrollHeight);
#my-div get filled using AJAX. So in my ajax request, I've got a success callback which performs the above code:
$.ajax({
url: 'getLog.php',
data: {'logFile': 'log.php'}, // echo "<ul> A BUNCH OF <li>s here </ul>"
success: function(data){
$("#my-div").html(data);
// console.log($("#my-div ul")[0].scrollHeight); // Debugging Purposes
$("#my-div ul").scrollTop($("#my-div ul")[0].scrollHeight);
}
});
I went ahead and console logged $("#my-div ul")[0].scrollHeight (As you can see in the code) to see if it knows the scrollHeight before performing .scrollTop() And it worked (It showed 720 Then i increased the size of the log file, and then i refreshed, it showed 830)
The surprising thing is, when i goto the console (Chrome) and enter
$("#my-div ul").scrollTop($("#my-div ul")[0].scrollHeight);
It works perfectly, and the ul scrolls all the way to the bottom!
I can't figure out why it's not working though... :(