I am trying to use the DOM method to display a JSON object that I created inside of my .js file, and I need to display it in the HTML page. This is what my code looks like and it is not working.
function JSONMethod(){
carInfo = {"make":"BMW", "model":"M5","mear":"2017","color":"Black"};
myJSON = JSON.stringify(carInfo);
localStorage.setItem("theJSON", myJSON);
text = localStorage.getItem("theJSON");
obj = JSON.parse(text);
for(var i = 0; i < obj.length; i++)
{
var para = document.createElement("li");
var node = document.createTextNode(obj[i]);
para.appendChild(node);
var element = $("display");
element.appendChild(para);
}
}
The $ function is this
function $(theId){
return window.document.getElementById(theId);
}