I have some text in a <p>
tag and a modal containing a <textarea>
.
When the user clicks on the modal, I copy the text from the <p>
into the textarea like so:
$(function() {
var temp = $('.messageContent p').text();
$('#messageBox').val(temp);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="messageContent">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in </p>
</div>
<textarea cols="50" rows='10' id="messageBox"></textarea>
<p><span>0</span> line</p>
After I copy the text, I want to determine how many lines of text are in the textarea. For this count, I need to include both explicit line breaks (i.e., pressing Enter) as well as implicit breaks caused by word wrapping.
My code will be functional when the <span>
in the snippet above updates to show the number of lines written in the textarea.