This is how I'd do it, though obviously the mark-up is only generic and to be amended to your needs:
html
<div class="counter"></div>
<textarea></textarea>
<div class="tmp"></div>
CSS
textarea, div {
width: 150px;
resize: none;
border: 1px solid #ccc;
padding: 0;
margin: 0;
font-size: 1em;
font-family: Arial, sans-serif;
}
textarea {
height: 85px;
}
div {
min-height: 85px;
}
jQuery:
$('textarea').keyup(
function(e){
var t = $(this).val();
$(this).next('.tmp').text(t);
$(this).prev('.counter').text('Height is: ' + $(this).next('.tmp').outerHeight());
});
JS Fiddle demo.
This could be amended to dynamically add, and remove, the .tmp
div
s as required. But I was trying to keep this as simple as possible, so I left it hard-coded.
References: