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

210
Visualizações
JavaScript - Contenteditable bold option without execCommand

I want to create a simple WYSIWYG editor with contenteditable and a bold option. This used to be really easy to achieve using execCommand as can be seen here.

Unfortunately execCommand is now deprecated.

My approach to achieve this without execCommand would be the following:

  1. Get selection with window.getSelection()
  2. Convert the selection to a text node on which I can set innerHTML and make sure it is a descendant of the contenteditable div
  3. Do a simple transform of the innerHTML (e.g. node.innerHTML = '<b>' + node.innerHTML + '</b>')

However, I am not sure how to achieve the second part. window.getSelection().anchorNode returns the correct node, but it won't let me set innerHTML or innerText on it.

Is this even possible? Thanks in advance!

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