var divCopy = document.getElementById('copyText'),
nmbrBox = document.getElementById('numbers'),
txtBox = document.getElementById('textBox'),
lineHeight = 20;
function addEvents() {
"use strict";
txtBox.addEventListener("keyup", copyText, false);
txtBox.addEventListener("keyup", addLines, false);
}
function copyText() {
"use strict";
var txtBoxVal = txtBox.value;
txtBoxVal = txtBoxVal.replace(/(?:\r\n|\r|\n)/g, '<br />');
divCopy.innerHTML = txtBoxVal;
}
function addLines() {
"use strict";
var lines = divCopy.offsetHeight / lineHeight, x = 1, holder = '';
for (x = 1; x <= lines; x = x + 1) {
holder += '<div class="row">' + x + '.</div>';
}
if (lines === 0) {
holder = '<div class="row">1.</div>';
}
nmbrBox.innerHTML = holder;
}
window.addEventListener("load", addEvents, false);
html, body{
font-size: 10px;
height: 100%;
}
textarea{
background: #f3f3f3;
color: #111;
font-family: sans-serif;
font-size: 1.8em;
line-height: 20px;
min-height: 600px;
min-width: 800px;
resize: none;
overflow: hidden;
position: absolute;
left: 56px;
}
textarea:focus{
outline: 0;
}
textarea, .rows{
display: inline-block;
}
.rows{
background: #e3e3e3;
box-sizing: border-box;
color: #999;
font-family: monospace;
font-size: 1.8em;
height: 100%;
line-height: 20px;
max-height: 600px;
overflow: hidden;
padding: 0.16em 0em;
text-align: right;
width: 48px;
vertical-align: top;
}
#copyText{
display:inline-block;
font-family: sans-serif;
font-size: 1.8em;
line-height: 20px;
visibility: hidden;
}
<div class="container">
<div class="rows" id="numbers">
<div class="row">1.</div>
</div>
<textarea rows="30" id="textBox"></textarea>
<div id="copyText"></div>
</div>
<script src="script.js" type="text/javascript"></script>