-1

This is my code:

var message;
var ul = $('.chat');
var btn = $('#btnEnviar');

btn.click(()=>{
  message = $('#Mensaje').val()
  ul.append('<li>'+message+'</li>');
})
$('#Mensaje').keyup((e)=>{
  (e.which === 13) && ul.append('<li>'+$('#Mensaje').val()+'</li>')
})

rest of the code is here:
[https://codepen.io/willmsha/pen/zyQVPb][1]

As you guys can see that I have to scroll down after few times of adding new message to the ul.

Is there any chance to prevent that except using something like this:

window.scrollTo(0,document.body.scrollHeight);



So what I wanna do is something like to append the li tag to the bottom of the ul, so I wont have to scroll down when a new mesage is added.

Developer Tanbir
  • 346
  • 2
  • 13
  • `append` already always adds to the bottom. If you want to keep the screen at the bottom, see [this question](https://stackoverflow.com/q/37300618/215552). – Heretic Monkey Jan 18 '19 at 00:21
  • 1
    Please post your code here using a StackOverflow snippet instead of referencing external code sites. – connexo Jan 18 '19 at 00:26
  • @HereticMonkey thank you, that was kinda what i was looking for. connexo actually tried to but failed – Alden Willms Jan 18 '19 at 08:43