Automatically Adding Line Breaks in Textarea

Here’s an example of how to add linebreaks in your HTML textarea every x amount of characters using jQuery.

Simply change 50 to your desired length of characters you allow per line.

$("textarea").keyup(function(e) {
    var $this = $(this);
    var length = $this.val().length;
    if(length % 50 == 0) {
        $this.val($this.val() + "\n");
    }
});

Leave a Reply

Your email address will not be published. Required fields are marked *