Add line breaks after n numbers of letters in long words

javascript, jquery

Solution

Here is one option:

string.match(/.{1,10}/g).join("<br/>");

Problem

A have a string that can reach up to 100 characters in lenght. Is there an easy way to insert line breaks in the word every 10th letter? For example: ``` aaaaaaaaaaaaaaaaaaaaaaaaa ``` Should turn in to ``` aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaa ``` I know that i can modify html with the html() method, but im not sure how to count characters and insert the tags. Thanks

Original source