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

207
Views
En window.getSelection tenemos que hacer una etiqueta de intervalo en el conteo de rango

mi página html contiene esta línea

 <p id='str'> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ipsam repellat iste accusantium laboriosam rem commodi, quisquam libero minima. Quo neque dolore<span style="background-color: yellow;">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consectetur, totam.</span> ratione fuga magni accusantium dolorum culpa, dolorem quasi atque voluptates illo, facilis magnam temporibus quam iste est voluptatum, quisquam optio? Inventore laborum, repellat quaerat ipsum aspernatur ab perspiciatis modi. </p>

y mi código Javascript esta línea

 let str = document.getElementById('str'); str.addEventListener('mouseup',(e)=>{ let range = window.getSelection().getRangeAt(0); console.log("startOffset" ,range.startOffset); })

cuando selecciono

el img es su descripción de la imagen ingrese aquí

Pero cuando selecciono de la etiqueta span, su img es la siguiente

el img es su descripción de la imagen ingrese aquí

El startOffset es el mismo cuando selecciono inicio, pero cuando selecciono de la etiqueta span, el startOffset se convierte en 0, pero tengo que contarlo con su cadena principal.

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!