@pete I originally made a script like this for my site over a year ago, but later decided that I didn’t necessarily want a drop cap on every page, so I opted for hardcoding the classes.
I obviously didn’t think through all the details, but here is what my code looked like using the .html() property. No consideration for html tags, or characters other than letters in the first position.
function dropCap(el){
var str = ( $(el).html());
var firstletter = str.substr(0,1);
var replaced = str.replace( firstletter ,”<span class=’ dropcap’>” + firstletter + ”<\/span>”);
$(el).html(replaced);
}
@pete I originally made a script like this for my site over a year ago, but later decided that I didn’t necessarily want a drop cap on every page, so I opted for hardcoding the classes.
I obviously didn’t think through all the details, but here is what my code looked like using the .html() property. No consideration for html tags, or characters other than letters in the first position.
function dropCap(el){ var str = ( $(el).html()); var firstletter = str.substr(0,1); var replaced = str.replace( firstletter ,”<span class=’ dropcap’>” + firstletter + ”<\/span>”); $(el).html(replaced); }
posted by John Dilworth on Thursday, Dec 04, 2008