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); }
$('#display)or some other valid selector. 2) Objects don't have alengthproperty. Try afor..inloop. 3) All that local storage stuff is completely superfluous to your question$being defined. Seems like something only Chrome and Firefox do ~ stackoverflow.com/questions/22244823/…