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

238
Views
get a javascript object as a link

I need your help; i want the name obtained from the json array to be a link; that is, once I get the name I click on it to be directed to a page (for example, it is assumed www.google.com). To do this I used the following line:

document.getElementById("demo").innerHTML = "+myObj["name"]+";

but I get nothing. Can anyone help me please?

const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = "<a href='http://www.google.com'>+myObj["
name "]+</a>";
<h2>Access a JavaScript Object</h2>
<p id="demo"></p>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

document.getElementById("demo").innerHTML = "<a href='http://www.google.com'>"+myObj['name']+"</a>";

or

document.getElementById("demo").innerHTML = `<a href='http://www.google.com'>${myObj["name"]}</a>`;
about 4 years ago · Juan Pablo Isaza Report

0

Use template literals

<html>
<body>

<h2>Access a JavaScript Object</h2>
<p id="demo"></p>

<script>
const myJSON = '{"name":"John", "age":30, "car":null}';
const myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = `<a href='http://www.google.com'>${myObj["name"]}</a>`;
</script>

</body>
</html>

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!