How to Capitalize first letter jquery

div class=’capitalize’
    SOMETHING BETTER
    SOMETHING BETTER
    SOMETHING BETTER
div
.capitalize {
    text-transform: lowercase;
}
.capitalize span {
    display: inline-block;
    padding-right: 0.5em
}
.capitalize span:first-letter {
    text-transform: uppercase !important;
}
$(‘.capitalize’).each(function(){
    var text = this.innerText;
    var words = text.split(” “);
    var spans = [];
    var _this = $(this);
    this.innerHTML = “”;
    words.forEach(function(word, index){
        _this.append($(‘<span>’, {text: word}));
    });
});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: