Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda