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

165
Views
Using Document.getSelection on a div of contentEditable true which contains HTML tag

I am trying to build a text editor from scratch using Reactjs.

I am trying to use a div of contentEditable true which contains HTML tags like anchor tag etc. To select any string I am using the following code -

 var sel = document.getSelection()

If there is no tag, the selection object takes all content of div as a single part. But if there is an HTML tag, then the selection object works for children objects separately. i.e. selection.achorOffset returns value counting from the end of the previous HTML tag.

Try selecting content by more than one row

So far I did up to like this

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!