Preventing display of orphans in text using JavaScript
“...I then figured that if we could automatically replace a regular space with a between the two words at the end of a paragraph, this would mean they would get treated as a single word and so would break onto a new line together.Hooray!
With a few lines of jQuery code, we can prevent widows and orphans as shown below:”
$('p').each(function(){ var string = $(this).html(); string = string.replace(/ ([^ ]*)$/,' $1'); $(this).html(string); });
Source: link












