I have a string that is supposed to go into a text message, however the text keeps going off the box, i want to wrap the text in the div. I want to split the string so that every 17 characters or so, a
tag is inserted so that it moves to the new. I would need to split the string along the spaces to keep the words whole, but would need to make sure the total characters in a line don't go over 17.
Are there any other methods that i am not seeing? maybe a wrap text feature on Jquery?
right now i do the following code:
var newMessageArr = message.match(/.{1,15}/g);
var splitMessage = '<li class="replies"><p>' + newMessageArr[0];
for (var i = 1; i < newMessageArr.length - 1; i++) {
splitMessage += '<br>' + newMessageArr[i];
}
splitMessage += '</p></li>';
$(splitMessage).appendTo($('.messages ul'));
this makes the message into an array, and inserts a br tag at the given interval, the only problem is that it cuts the words off.
Any help is much appreciated, new to front end so go easy if there is something obvious that im missing...