1
I create a modal box that has a textarea, when clicking the send button I need to know how many characters there are in the textarea. Trying to use Jquery to find this size has not returned anything to me. How can I solve this problem?
1
I create a modal box that has a textarea, when clicking the send button I need to know how many characters there are in the textarea. Trying to use Jquery to find this size has not returned anything to me. How can I solve this problem?
3
Since you can capture this element, there is no problem in counting how many characters Textarea has.
Just use the method val()
which returns a string with all the inserted text and then uses the property length
.
$('#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>
<textarea id="txtArea"></textarea> <br>
<button id="click-me">Clique</button>
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 size of its value:
Browser other questions tagged javascript jquery html
You are not signed in. Login or sign up in order to post.
How did you create the textarea? As you already tried to do?
– Jéf Bueno