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

100
Views
how to safely truncate text containing html tags with javascript

I have a string like this:

Hello world!<br />this is a new day for us<br /><br />lorem ipsum dolor and more long string here

and I need to only show the first 15 characters.. how do I do that? if possible I want to use only vanilla js (no jquery)

I thought of these steps:

  1. get rid of the html tags

  2. use substr to truncate the string

but some people says that using regex myString.replace(/<[^>]*>?/gm, ''); in javascript to strip html tags is not 100% dependable.. (link here) so now I don't know what to do. any help is appreciated

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!