Apply the plugin to whatever tags you want:
$('h1, p').widows();
Be sure that the tags will only contain text content. This will strip HTML content out of the tags passed into it.
| (function($){ | |
| $.fn.widows = function(){ | |
| $(this).each(function(){ | |
| $(this).html( | |
| $(this).html().replace( | |
| / ([^ <]*)([\<\/\w*\>]*)$/, | |
| function(_, last, tag) { return '\xa0' + last + tag } | |
| ) | |
| ); | |
| }) | |
| } | |
| }(jQuery)); |