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

142
Views
RE-selecting text after losing focus on editablecontent div

I have the following code:

<div id="textBox" contenteditable="true"></div>

I use the following code to get the selected text within the div.

if (document.getSelection) {
    var sel = document.getSelection();
    selRange = sel; 
    return sel;
}

As you can see, I save the selected range in a global variable called selRange.

What I want is to be able to reSELECT the previously selected text once it has been deselected after the user has clicked away.

What I've noticed is that range saves the startOffSet which is always 0 and the focusOffset which ends up being the length of the selected range (this is true when the code in the div looks like this: test <strong>test</strong> test). But nothing else about where in the full text the user has selected.

Is that possible?

Thanks

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!