Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
De todos modos, para que el método getSelection ignore las etiquetas html

Quiero guardar el rango y después de recargar la página, use esos valores para resaltar (con color amarillo, por ejemplo), pero el problema es que getRangeAt (0) no devuelve el rango correctamente. sus rangos se reinician después de cualquier etiqueta html, ¿cómo puedo resolver este problema?

 <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); } }); });

en este caso getRangeAt(0) devuelve 0,4 si selecciono "hola", luego si selecciono "John" devuelve 0,4 nuevamente.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!