Last active
June 20, 2019 14:58
-
-
Save alyssawilliams/acc2900ca84d4f114cf5a9040736a9e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inserts a non breaking space character between the last two words in each text block, to prevent widows | |
$('.selector').each(function() { | |
var words = $(this).text().split(' '); | |
var replacement = words[words.length - 2] + '\xA0' + words[words.length - 1]; | |
words.splice(words.length - 2, 1, replacement); | |
words.pop(); | |
var updatedString = words.join(' '); | |
$(this).text(updatedString); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment