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

216
Visualizações
How can i wrap the new word in a content editable?

I have an input (content editable), so i want to write in it and wrap the new word (after that write space) as a span like this:

old content <span class='el'>newWord</span> //old content

also the older content could be content with <span> or not but should not be modified

only should be wrap the new word, the old content should stay as before without changes

var something = document.getElementById('something');

something.addEventListener('keydown', (event) => {
  const text = something.innerHTML
  if (event.keyCode == 32) {
    var split_text = text.split(' ');
    console.log(split_text)
    var _out = [];
    let count = split_text.length;
    for (var i = 0; i < count; i++) {
      _out[i] = `<span class=el>${split_text[i]}</span>`
    }
    something.innerHTML = _out.join(' ')
  }
})
.el {
  background-color: red
}
<div id="something" contenteditable>
  here
</div>

about 4 years ago · Juan Pablo Isaza
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