0

How do I wrap very long text in jGrowl?

Right now, if the text is long it just tosses out of the page.

Thanks.

James Wiseman
  • 29,946
  • 17
  • 95
  • 158
Hulk
  • 32,860
  • 62
  • 144
  • 215
  • 2
    I *assume* you're talking about text that has no spaces is too long for the jgrowl box. Is that right? Do you want it to wrap to a new line at some arbitrary point in the text? What does the text look like? Is it a specific case where this is happening, which would allow us to create a logical break point? – user113716 Feb 22 '10 at 14:38

1 Answers1

2

Well Hulk, since we haven't gotten any more info from you, I'm just going to take a stab at a solution.

This will break any long text after 15 characters. (Of course, you can substitute whatever number you want.)

This assumes there are no HTML tags. Just text.

var theText = $('.myContainer').text().split(' ')
jQuery.each(theText,function(i,val){
    theText[i] = val.replace(/^(\S{15})(\S+)/,'$1 $2')
})
$('.myContainer').text(theText.join(' '));
user113716
  • 318,772
  • 63
  • 451
  • 440