that was rather fun
<script>
(function() {
[].forEach.call(document.querySelectorAll('[title]'), function(element) {
var words = element.title.split(/\s+/);
var capitalized = words.map(function(word) {
return word[ 0 ].toUpperCase() + word.slice(1);
});
element.title = capitalized.join(' ');
});
})();
</script>
I first selected all the elements with a title attribute (querySelectorAll('[title]')
), then I go over each of the elements, extracting the title itself and splitting it to words using .split
that works on all the whitespace. Then I iterate over the words, mapping each word to its capitalized word (take the first letter, capitalize it, and add the rest of the word).
At the end I simply join back the words using a space.