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?
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?
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>
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: