http://learn.javascript.ru/play/jGjdg
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
.container {
border: 1px solid #000;
height: 300px;
overflow: hidden;
}
.container div {
margin: 5px 0;
}
</style>
</head>
<body>
<div class="container">
</div>
<script type="text/javascript">
var container = document.querySelector('.container'),
div, n = 0;
while(true) {
div = document.createElement('div');
div.innerHTML = ++n;
container.appendChild(div);
if(container.scrollHeight > container.clientHeight) {
container.removeChild(div);
break;
}
}
</script>
</body>
</html>