0

I am using this code to set scrolled to bottom when the page lodes -

$(document).ready(function(){
    $('#chat_message_inner_container').scrollTop( $('#chat_message_inner_container')[0].scrollHeight);
  });

And I want to use this code also -

  setInterval(function()
  {
    $('#chat_message_inner_container').load(location.href + " #chat_message_inner_container");
  },1000);

But it is not working. How can I do this ?

Abhijit
  • 11
  • 3

1 Answers1

1

your scroll instruction should be executed on the load function callback and not on ready

 setInterval(function () {
            $('#chat_message_inner_container').load(location.href + "#chat_message_inner_container", {}, function () {
                $('#chat_message_inner_container').scrollTop($('#chat_message_inner_container')[0].scrollHeight);
            });

        }, 1000);
mondersky
  • 441
  • 2
  • 15
  • But the problem is, it is creating another new div within #chat_message_inner_container this div. – Abhijit Apr 19 '23 at 10:03
  • then you're approach isn't the right one, you should use load on a different div and then get the data from that div using the html method and place it inside your final target – mondersky Apr 19 '23 at 11:54
  • If you want to scroll the div down on page load, you have not to use $(document).ready(function(), but $(document).load(function().Ready is when DOM is ready, load was executed when the page is shown in the browser. Look at this! I think this is the solution: [link]https://stackoverflow.com/questions/23351402/load-performance-issue-when-using-in-interval – Achim Udo Apr 25 '23 at 16:21