Skip to content

Instantly share code, notes, and snippets.

@siffring
Created April 1, 2010 14:45
Show Gist options
  • Save siffring/351881 to your computer and use it in GitHub Desktop.
Save siffring/351881 to your computer and use it in GitHub Desktop.
// wraps the first character of a paragraph with <div class="dropclass"></div>
// expects a jQuery paragraph object
// ex: dropCap($('.story p:first'));
function dropCap($target) {
$first_p = $target.html().trim(); // removes any leading whitespace
if ($first_p.charAt(0) != '<') {
// not a html tag
$target.html( '<div class="dropcap">' + $first_p.charAt(0) + '</div> ' + $first_p.substring(1) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment