Created
December 10, 2013 13:41
-
-
Save tjhole/7890717 to your computer and use it in GitHub Desktop.
JQUERY: Add non-breaking space to titles to prevent widows
This file contains hidden or 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
$structure(document).ready(widow); | |
function widow(){ | |
$structure("h1,h2,h3,h4,h5").each(function() { | |
var wordArray = $structure(this).text().split(" "); | |
var finalTitle = ""; | |
for (i=0;i<=wordArray.length-1;i++) { | |
finalTitle += wordArray[i]; | |
if (i == (wordArray.length-2)) { | |
finalTitle += " "; | |
} else { | |
finalTitle += " "; | |
} | |
} | |
$structure(this).html(finalTitle); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment