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

134
Views
Parse and modify an html string in JavaScript

I have this string HTML. it can have many href attributes.

"<h4> TITLE </h4> <p>test</p> 
<a\r\n class=\"link\"\r\n target=\"_blank\" \r\n href=\"https://test.com\">\r\n LABEL HERE </a>.\r\n </p>\r\n     
<a\r\n class=\"link\"\r\n \r\n href=\"https://test2.com\">\r\n LABEL HERE 2 </a>.\r\n </p>\r\n" 

I need to loop to every a href and modify it and return it to something like this below: add text in the label. and add target="_blank" in the href attribute if it's not there yet. Would really appreciate the help. tried many things but couldn't get this to work.

"<h4> TITLE </h4> <p>test</p>  
 <a\r\n class=\"link\"\r\n \r\n target=\"_blank\" href=\"https://test.com\">\r\n LABEL HERE (ADD TEXT HERE)</a>.\r\n </p>
 <a\r\n class=\"link\"\r\n \r\n target=\"_blank\" href=\"https://test2.com\">\r\n LABEL HERE2 (ADD TEXT HERE)</a>.\r\n </p>" 

EDIT: tried this code but im getting the "expression is not callable, string has no call signatures" in the el.innerHTML code.

  let consentDataxString: string = dataFromApi?.selectedData.toString() || '';
  let el = document.createElement( 'html' )
  el.innerHTML(consentDataxString)
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!