Skip to content

Instantly share code, notes, and snippets.

@gauravsaini23
Created February 12, 2013 12:00
Show Gist options
  • Save gauravsaini23/4761870 to your computer and use it in GitHub Desktop.
Save gauravsaini23/4761870 to your computer and use it in GitHub Desktop.
apply maxlength attribute to textarea (for ie)
$('textarea[maxlength]').live('keyup blur', function() {
// Store the maxlength and value of the field.
var maxlength = $(this).attr('maxlength');
var val = $(this).val();
// Trim the field if it has content over the maxlength.
if (val.length > maxlength) {
$(this).val(val.slice(0, maxlength));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment