This time I will share jQuery Plugin and tutorial about Limit The Character Length In A Textarea – jQuery writeLimit.js, hope it will help you in programming stack.
writeLimit.js is a small jQuery plugin used to limit the character length in a textarea element. With a custom feedback that displays the current/maximum character length.
Also supports copy/paste events and automatically deletes the excess characters after typing/pasting.
How to use it:
1. Create an element next to the textarea element that will be used to display the feedback messages:
1 |
< textarea id = "input-field" ></ textarea > |
2 |
< div id = "feedback-field" >0/140 Characters</ div > |
2. Include jQuery library and the writeLimit.js
script at the bottom of the webpage.
2 |
integrity = "sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" |
3 |
crossorigin = "anonymous" > |
5 |
< script src = "writeLimit.js" ></ script > |
3. Call the function on the textarea element with the following parameters:
- feedback: the selector of feedback element
- limit: character limit
- addon: characters to be appended to the feedback message
2 |
$( "#input-field" ).writeLimit( "#feedback-field" , 140, "Characters" ); |
This awesome jQuery plugin is developed by dsheedes. For more Advanced Usages, please check the demo page or visit the official website.