Last active
October 2, 2015 20:58
-
-
Save inkbase/2320961 to your computer and use it in GitHub Desktop.
jQuery: Adopt orphans plugin
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
// Plugin for removing orphans from pieces of text. | |
// Inspired by http://www.learningjquery.com/2008/07/three-quick-ways-to-avoid-widows | |
// Author: Jason Landry | |
// Web: http://inkbase.com | |
(function( $ ){ | |
$.fn.adoptOrphans = function() { | |
this.each(function() { | |
var result = ''; | |
var array = $(this).html().split(' '); | |
var lWord = array.pop(); | |
result = array.join(' ') + ' ' + lWord; | |
$(this).html(result); | |
}); | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment