Get the size of a textarea that was added dynamically

1

I create a modal box that has a textarea, when I click the Send button I need to know how many characters there are in the textarea. Trying to use JQuery to match this size did not return anything to me. How can I resolve this problem?

    
asked by anonymous 09.03.2017 / 19:01

2 answers

2

Since you can capture this element, there is no problem counting how many characters TextArea has.

Just use the val() method that returns a string with all text entered and then use the length property.

$('#click-me').on('click', function(){
  var qtd = $('#txtArea').val().length;
  console.log(qtd);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><textareaid="txtArea"></textarea> <br>
<button id="click-me">Clique</button>
    
09.03.2017 / 19:07
1

This should work for you:

$('#textarea_1').val().length

I put in a fiddle a code that creates a textarea dynamically, and takes the value size of it:

link

    
09.03.2017 / 19:07