jquery-unorphanize
jquery-unorphanize copied to clipboard
A small jQuery method for preventing orphans in text
jQuery Unorphanize
A small jQuery method for preventing or stopping orphans (widows) in text, paragraphs or whatever (unhindered by HTML).
~ 500 bytes minified
How it works
$(".selector").unorphanize();
Unorphanize will take the jQuery selector ( $(".selector")
) you supply
and without disturbing theinner html's markup will replace the last space
with an
preventing an orphan
from occurring.
If you wish the last line to have more than 2 words, you can supply an argument in number
format like so:
$(".selector").unorphanize(2);
Why it's better than "Plugin X"
Unorphanize will recognize if you have HTML elements, and not ruin them: Most other plugins will do it a bit faster,
but they will ignore HTML tags and put the space before/after them, or they will just not work.
They may also put the space inside of a html entity like: <a href="#">blah</a>
which as you can imagine is useless.
You should, however, run it before you bind events to inner dom elements, or you may lose those events. Or you can
delegate events from the parent element.
Example
A Line of text which wraps and leaves an
orphan.
would change to:
A line of text which wraps and leaves
an orphan.
and with $(".selector").unorphanize(2);
we get:
A line of text which wraps and
leaves an orphan.