<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
.container {
border: 1px solid #000;
height: 300px;
overflow: hidden;
}
.container div {
margin: 5px 0;
}
.sd {
color: red;
font-weight: bold;
}
</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.className = 'sd'
div.innerHTML = ++n;
container.appendChild(div);
if(container.scrollHeight > container.clientHeight) {
container.removeChild(div);
break;
}
}
</script>
</body>
</html>