So I’m trying to make it so that when a user presses the “send” button, the text typed into the input “messageInput” will appear in a new
element inside the div “content”.
(js)
document.getElementById(“send”).onclick = function() {
var message = document.getElementById(“messageInput”).value;
if (message == “”) {
// nothing
} else {
var message = document.getElementById(“messageInput”).value;
var para = document.createElement(“p”);
var node = document.createTextNode(message);
para.appendChild(node);
var element = document.getElementById(“content”);
element.appendChild(para);
}
}
I took this code from w3schools so I’m unsure why there’s an error. The error is basically “Uncaught TypeError: Cannot read property ‘appendChild’ of null”. The error occurs at the line “element.appendChild(para)”.
Alright, sorry if this was a repeat, it didn’t seem to be one when I checked, and apologies if my error is extremely obvious. Thanks in advance.