Created
October 5, 2013 01:39
-
-
Save phamquocbuu/6835562 to your computer and use it in GitHub Desktop.
JavaScript Limit textarea text length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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