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

144
Vistas
RE-selecting text after losing focus on editablecontent div

I have the following code:

<div id="textBox" contenteditable="true"></div>

I use the following code to get the selected text within the div.

if (document.getSelection) {
    var sel = document.getSelection();
    selRange = sel; 
    return sel;
}

As you can see, I save the selected range in a global variable called selRange.

What I want is to be able to reSELECT the previously selected text once it has been deselected after the user has clicked away.

What I've noticed is that range saves the startOffSet which is always 0 and the focusOffset which ends up being the length of the selected range (this is true when the code in the div looks like this: test <strong>test</strong> test). But nothing else about where in the full text the user has selected.

Is that possible?

Thanks

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