Issue
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>
Solution
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>`;
Answered By - mr.rusik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.