Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AmineBHD's avatar

scroll down to the last item

I'm working on chat application and i would like to scroll down to the last message received, I'm using Vuejs3 Itried a lot of plugins and codes, didnt worked for me this is my div :

     <div class="chat-history" style="height: calc(100vh - 60px - 50px);overflow-y: auto;">
                    <ul class="m-b-0" id="communication">
                        <li> Msg 1 </li>
                        <li> Msg 2 </li>
                        <li> Msg 3 </li>
                    </ul>
                </div>
0 likes
5 replies
tykus's avatar
tykus
Best Answer
Level 104

Get the last child, and use the scrollIntoView

 let el = document.getElementById('communication').lastElementChild;
 el.scrollIntoView({behavior: 'smooth'});
AmineBHD's avatar

@tykus created() { let el = document.getElementById('communication').lastElementChild; el.scrollIntoView({behavior: 'smooth'}); }

Error : Uncaught TypeError: document.getElementById(...) is null

tykus's avatar

@AmineBHD too soon, the component is not rendered. You can use $nextTick to wait

1 like

Please or to participate in this conversation.