I'm trying to print out a JS data into an HTML DOM. I couldn't get it to print. What did I do wrong ?
<!DOCTYPE html>
<html>
<head>
<title>JSON</title>
<script type="text/javascript">
// user is the property of obj1
var obj1 = {
user: "John",
age: 26,
country: "United States"
};
document.getElementById("results").innerHTML = obj1.user + "<hr>";
</script>
</head>
<body>
<div id="results"></div> <---- Expected to see John HERE
</body>
</html>
In my console
Uncaught TypeError: Cannot set property 'innerHTML' of null