function scrollSmoothToBottom (id) { var div = document.getElementById(id); $('#' + id).animate({ scrollTop: div.scrollHeight - div.clientHeight }, 500); } function total_peers() { $.post('/total_peers',null,function(result){ $("#total_peers").html(result) }); } setInterval(function() { total_peers() $.post('/get_messages', null, function(result) { $('#messages_display').html(null); parsed_response = JSON.parse(result) parsed_response.forEach(function(item){ if((item['from']+'/') == window.location.href) { $('#messages_display').append("
" + item['message'] + "
" + item['from'] + "" + item['message'] + "
" + message + "