I have the following code adapted from a previous question/answer:
var str = $('title').text();
str = str.toLowerCase().replace(/\b[a-z]/g, convert);
function convert(){
return arguments[0].toUpperCase();
}
$('title').text(str);
I need to add some exceptions to this such as ‘and’.
Thanks in advance.
You could build an
Arrayof the exceptions and check to see if the matched string matches.If so, just return it as is.
jsFiddle.