capitalise 5

by bizwizone

HTML

<div class="title">Me & you 
    <div class="subtitle">Me & you</div>
</div> 
<br /> 
<div class="title">Me & you</div>

CSS

th {border: 1px solid red;}

JavaScript

function capitalise(str) {
    if (!str) return;
    var stopWords = ['a', 'an', 'and', 'at', 'but', 'by', 'far', 'from', 'if', 'into', 'of', 'off', 'on', 'or', 'so', 'the', 'to', 'up'];
    str = str.replace(/\b\w+\b/ig, function(match) {
        console.log(match)
        return $.inArray(match, stopWords) == -1 ? match.substr(0, 1).toUpperCase() + match.substr(1) : match;
    });
    return str;
}



var fcn = $('div.title').contents().filter(function() { return this.nodeType === 3;});

alert(fcn);
console.log(fcn);