0

I wrote this script to capitalize first letter of title or if URL contains giocatori_ first letters of name until '-' (Giovanni Rossi) but the if it doesn't work.

$(document).ready(function(){
    function capitaliseFirstLetter(string){
        if (/giocatore_/.test(window.location)) {
            var title = document.title;
        subTitle = title.split('-')[0];
        subTitleNext = title.split('-')[1];
        subTitle=subTitle.replace('_',' ');

        subTitle = subTitle.toLowerCase().replace(/\b[a-z]/g, function(letter) {
            return letter.toUpperCase();
        })


        document.title = subTitle+' - '+subTitleNext;
    } else {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
    document.title = capitaliseFirstLetter(document.title);
});

Any suggestion?

Thanks

roybatty
  • 191
  • 3
  • 13

1 Answers1

0

After looking at another thread: How do I check if string contains substring?

I think you might be missing the i flag from your statement, which makes the match case-insensitive.

if (/giocatore_/i.test(window.location)) {
Community
  • 1
  • 1
Mike GB
  • 178
  • 12