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

80
Views
Creating a Range at a specific point

I tried to create a range, which leads to a specific point in the text, but this was very difficult with the ChildNodes, because you can't reach exactly one point in the text, but only for example the beginning or end of a ChildNode.
I there a way to reach the point between „te“ and „st“ (like putting the cursor between „te|st“) or is it possible to create a range independent of the childnodes?

Here is my Code:

function myFunction(el) {
    var textNode = el.childNodes[1];
    var range = document.createRange();
    range.selectNodeContents(el);
    range.setStart(textNode, 0);
    range.setEnd(textNode, 0);
    var sel = window.getSelection();
    sel.removeAllRanges();
    sel.addRange(range);
}
<!DOCTYPE html>
<html>
<body>

<div id="myText" contenteditable>test<br>test</div>

<button type="button" onclick='myFunction(document.getElementById("myText"))'>Go into Text</button>

</body>
</html>

Thank you for every help!

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!