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

288
Views
How can I convert string returned from API call to proper HTML in javascript?

I am calling an API command("@ReportProperty2(45899,exportdata,,'16115898')@") which returns HTML of the button but in string format and > and < are in &gt; and &lt; and there are double quotes are well which breaks my code at the following line:

const aaa = "@ReportProperty2(45899,exportdata,,'16115898')@";

RESULT FROM THE COMMAND:

"&lt;button type=button class=Button onclick="openwp('1677008','RHpdFBx7GS9YGFEwFmUUCyE4Ih8lHyA!H2JbUENBa1BV')" &gt;&lt;i class="fa fa-pencil-square-o" style="margin: 0 4px 0 0"&gt;&lt;/i&gt;Enter Budget&lt;/button&gt;"

I have tried replacing but it is throwing "unexpected token: identifier" error.

How can I convert the result to the following:

<button type="button" 
        class="Button" 
        onclick="openwp('1677008','RHpdFBx7GS9YGFEwFmUUCyE4Ih8lHyA!H2JbUENBa1BV')">
  <i class="fa fa-pencil-square-o" 
     style="margin: 0 4px 0 0" 
     data-original-title="" 
     title="">
  </i>
  Enter Budget
</button>

Please see pic for more info: enter image description here

I tried Lodash unescape,decodeHTMLEntities by Slavik Meltser, decodeEntities but it doesn't work.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Depending on your template engine, there may be a more appropriate method, but assuming this @ output escapes as HTML, you can put it in an (non-rendered) HTML context:

<template id="aaa-html">@ReportProperty2(45899,exportdata,,'16115898')@</template>

Then you can select the element and read it from JavaScript:

const aaa = document.getElementById('aaa-html').innerHTML;
about 4 years ago · Santiago Gelvez 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!