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

200
Views
In window.getSelection we have to do span tag in range count

my html page contain this line

<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>

and my Javascript code this line

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

When i select

the img is his enter image description here

But when i selecte from the span tag,its img is as follows

the img is his enter image description here

The startOffset is the same when I select start but when I select from the span tag the startOffset becomes 0 but I have to count it with its parent string

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!