I need an area that automatically scrolls to the bottom when new text comes in from an ajax request
CSS
div.scroll {
height: 400px;
width: 95%;
overflow: auto;
/* border: 1px solid #666; */
background-color: #ccc;
padding: 8px;
}
HTML
<html>
<head>
<script type="text/javascript">
//Handle ajax data
$(document).ready(function()
{
setInterval(doAjaxStuff, 2000);
});
function doAjaxStuff()
{
$.ajax
({
url: "http:somewhere/getLog/",
dataType: 'json',
success: function(json)
{
if(json.status == "on")
{
$('#log').html(json.log);
}
}
});
</script>
</head>
<body>
<div class="scroll" id =log >pleas wait for log</div>
</body>
</html>
You can use the
scrollTop()function: