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

284
Views
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 answers
Answer question

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 Report
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!