jQuery Character Count


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $('textarea').each(function(){
  2. // get current number of characters
  3. var length = $(this).val().length;
  4. // get current number of words
  5. //var length = $(this).val().split(/\b[\s,\.-:;]*/).length;
  6. // update characters
  7. $(this).parent().find('.counter').html( 4000 - length + ' characters left');
  8. // bind on key up event
  9. $(this).keyup(function(){
  10. // get new length of characters
  11. var new_length = $(this).val().length;
  12. // get new length of words
  13. //var new_length = $(this).val().split(/\b[\s,\.-:;]*/).length;
  14. // update
  15. $(this).parent().find('.counter').html( 4000 - new_length + ' characters left');
  16. });
  17. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.