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

300
Vistas
Anyway for getSelection method to ignore html tags

I want to save the range and after reload of page use those values for highlighting ( with yellow color for ex.) but the problem is getRangeAt(0) does not return range correctly. it's ranges restart after any html tags, how can i solve this problem?

<p id="content">
  hello <br> John 
</p>

document.addEventListener("selectionchange", () => {
  $("#content").bind("touchend mouseup", function() {
    var t = window.getSelection();
    var range=t.getRangeAt(0);
    var text=t.toString();
                    
    if(text! = "") {
      var rect = range.getBoundingClientRect();
      var start=range.startOffset;
      var end=range.endOffset;
      console.log(start, ' = ', end);
    }
  });
});

in this case getRangeAt(0) return 0,4 if i select "hello", then if i select "John" it returns 0,4 again .

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