JSFiddle - React, Tailwind, and code Playground
HTML
<div class="title">me & you
<div class="subtitle">me & you</div>
</div>
<br />
<div class="title">me & you</div>
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) {
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;
}).replaceWith(function(){
return capitalise($(this).text());
});