JS - Force caplitalise elements from uppercase

0 votes
61 views
added Oct 9, 2024 in Javascript by lcjr First Warrant Officer (11,960 points)
document.querySelectorAll('.capcase td').forEach(function(td) {
    if (td.textContent) {
        td.textContent = td.textContent
            .toLowerCase()
            .split(' ')
            .map(word => {
                if (word.toUpperCase() === "TBC" || word.toUpperCase() === "NA") {
                    return word;
                } else {
                    return word.charAt(0).toUpperCase() + word.slice(1);
                }
            })
            .join(' ');
    }
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...