Skip to content

Instantly share code, notes, and snippets.

@somatonic
Created December 10, 2012 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save somatonic/4252962 to your computer and use it in GitHub Desktop.
Save somatonic/4252962 to your computer and use it in GitHub Desktop.
TextAreaCounter JScript
(function($){
$(function(){
$('textarea[data-maxlength]').each(function(){
$(this).bind("keyup change", function(){
var count = $(this).attr('data-maxlength') - $(this).val().replace(/\r?\n/g, '\r\n').length;
$(this).parent().find("span.counter span").text(count);
});
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment