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
Chrome contenteditable set caret at beginning of text node not work

I have a contenteditable element and want to set caret to at beginning of a text node. See example please. example

<p id="p" contenteditable="true">Example: <i>italic</i> and <b>bold</b></p>

let range = new Range();

range.setStart(p.childNodes[2], 0);
range.setEnd(p.childNodes[2], 0);

// toString of a range returns its content as text, without tags
console.log(range); // Example: italic
range.collapse(false);
// apply this range for document selection (explained later below)
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
p.focus();

When I typing (on Chrome), caret always at the end of the i tag, but I want it must at beginning of text node. That work on firefox but not on Chrome. 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!