This is my HTML :
<html>
<head>
<script src="domManipulating.js"></script>
</head>
// The DOM
<body>
<h1>
THE TITLE OF YOUR WEBPAGE
</h1>
<div id="container">
<div class="content">
This is the glorious text-content!
</div>
</div>
</body>
</html>
And this is my JS
var content = document.querySelector(".content");
var paragraph = document.createElement("p");
paragraph.textContent = " Hey I'm red";
content.appendChild(paragraph);
When I use the console to test my code a error appears :
Uncaught TypeError: Cannot read property 'appendChild' of null
From my understanding the variable content
can't hold document.querySelector(".content")
When I write document.querySelector(".content")
in the console it actually works but when I use var paragraph = document.createElement("p");
the variable turns into a null.
Why is that happening?