A beginners question.
I'm trying to add a button to an html document with no content.
In Chrome nothing shows up, but in the console there are no errors and I can find both btn with it's content and the div.
What's going on?
const div = document.createElement("div");
const btn = document.createElement("button");
btn.innerText = "Click me";
div.appendChild(btn);
btn.addEventListener("click", function() {
body.style.backgroundColor("red");
});
<body>
<script src="script.js"></script>
</body>
you should append your div to the body
document.body.appendChild(div);