Skip to content

Instantly share code, notes, and snippets.

@inkbase
Last active October 2, 2015 20:58
Show Gist options
  • Save inkbase/2320961 to your computer and use it in GitHub Desktop.
Save inkbase/2320961 to your computer and use it in GitHub Desktop.
jQuery: Adopt orphans plugin
// 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