0

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.

IronFlare
  • 2,287
  • 2
  • 17
  • 27
Raj
  • 69
  • 1
  • 5
  • look at [this](https://stackoverflow.com/questions/6501043/limit-number-of-lines-in-textarea-and-display-line-count-using-jquery) – Ahmed Sunny Sep 09 '19 at 12:09
  • Possible duplicate of [Limit number of lines in textarea and Display line count using jQuery](https://stackoverflow.com/questions/6501043/limit-number-of-lines-in-textarea-and-display-line-count-using-jquery) – Ahmed Sunny Sep 09 '19 at 12:10
  • Can you clarify what you mean by *"continuous typing"*? Are you referring to how often the line count should update, or are you talking about *word wrap*? – IronFlare Sep 09 '19 at 13:02
  • @IronFlare - Continious typing means, when the user type something in text area and the line comes to the second or nth line. – Raj Sep 09 '19 at 14:01
  • @AhmedSunny, nothing works out in these examples. – Raj Sep 09 '19 at 14:41

0 Answers0