Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
How to make exception for text-transfrom for a few words

I have this div that uses text-transorm: capitalize:

        <div style="display: flex;align-items:center; width: 400px; justify-content: space-between ;  max-width: 100%;">
            <p style="margin: 10px 0">Title</p>
            <input type="text" id="titleInput" style="width: 300px; text-transform: capitalize;"
                onkeyup="getIputValue(`titleInput`, `title`)" />
        </div>

And I need to find a way (probably add an if statement) to make an exception for a few words like "of" instead of "Of". What is your suggestion?

I wanted to use this function but it doesn't work. I know I'm missing something:

function lowerCasedWords() {
    let text = document.getElementById('titleInput').value;
    if (text.includes('Of') === 'true'){
        text.replace('Of', 'of')
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First you can't "mixt" CSS and Javascript. If you don't remove text-transform: capitalize; on the input no matter what your function does. Since you want to exclude some words it is better to do it all using JS.

Second the input value needs to be updated everytime a key is pressed (or maybe everytime the space key is pressed).

Last in your function it is not enought to replace 'Of' by 'of' you need to replace your input's value attribute.

Here is a working example

const input = document.getElementById('input');

const capitalize = word => {
  return word ? word[0].toUpperCase() + word.substr(1).toLowerCase() : '';
}

const noCapNeeded = ['of', 'a'];

input.addEventListener('input', evt => {
  input.value = input.value.toLowerCase().split(' ').map(word => {
    return noCapNeeded.includes(word)
      ? word
      : capitalize(word);
    }).join(' ');
});
<input type="text" id="input">

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda