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

286
Vistas
How to split a Text node to sub Text node with specified length?

I want to do something similar to splitText(), but with length, so if I have a Text node that contains the following string for example:

Hello please get *me* as a text node

Then only get *me* as a new Text node.

splitText() just splits into two so that's not working

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the normal String.split method, which is more straight forward if you know you want to split on the asterisk.

const textNode = document.body.firstChild
const text = textNode.data.split("*")[1]
const newTextNode = document.createTextNode(text)
document.querySelector("strong").append(newTextNode)
Hello please get *me* as a text node
<br> new textNode: <strong><strong>

You can also use substring.

const textNode = document.body.firstChild
const text = textNode.data.substring(22, 26)
const newTextNode = document.createTextNode(text)
document.querySelector("strong").append(newTextNode)
Hello please get *me* as a text node
<br> new textNode: <strong><strong>

about 4 years ago · Juan Pablo Isaza Denunciar
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