Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

77
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda