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

116
Vistas
deleting a mark tag within contentEditable div creates a font tag after retyping

When I use within a <div contentEditable> a <mark> tag the text is marked as expected.

When I now remove the marked tag with Backspace and start retyping some new characters after deleted the last one inside the content editable there is a <font style="..."><span style="...">new text created.

<div id="editable" contentEditable>
  Here is some <mark>text</mark> for testing!
</div>

This DOM is created after deleting the word text and replaced it with new text.

<div id="editable" contenteditable="">
  Here is some <span style="background-color: rgb(255, 255, 0);">new text</span>&nbsp;for testing!
</div>

How can I make the contentEditable to

  1. create the same tag as deleted or
  2. create no tag at all

when retyping?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I fixed it by calling the below function in the delete event by passing the HTML element to the function.

the calling:

placeCaretAtEnd(HTML_ELEMENT_OF_THE_CONTENT_EDITABLE);

the function:

placeCaretAtEnd(el) {
    el.focus();
    if (typeof window.getSelection != "undefined"
      && typeof document.createRange != "undefined") {
      var range = document.createRange();
      range.selectNodeContents(el);
      range.collapse(false);
      var sel = window.getSelection();
      sel.removeAllRanges();
      sel.addRange(range);
    }
  }
about 4 years ago · Juan Pablo Isaza Denunciar
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