Posted By

joeydi on 03/12/09


Tagged

count jquery


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

tshortt
vali29
jrutter
zoblue
kikuchiyosesa
vkolev
frysteen
firstpass


jQuery Character Count


 / Published in: jQuery
 

  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  

You need to login to post a comment.