/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('textarea').each(function(){ // get current number of characters var length = $(this).val().length; // get current number of words //var length = $(this).val().split(/\b[\s,\.-:;]*/).length; // update characters $(this).parent().find('.counter').html( 4000 - length + ' characters left'); // bind on key up event $(this).keyup(function(){ // get new length of characters var new_length = $(this).val().length; // get new length of words //var new_length = $(this).val().split(/\b[\s,\.-:;]*/).length; // update $(this).parent().find('.counter').html( 4000 - new_length + ' characters left'); }); });