How do I understand my addEventListener error code? [duplicate]

I’m attempting to build a simple ‘To-Do List’. I’m trying to add a new P element to my existing div. Does anyone have any ideas regarding the following error code?

Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

I feel like my HTML button (submitButton) click isn’t being received, although I could be wrong.

var toDoList = document.getElementById("toDoList"); // div with p elements within
var submitButton = document.getElementById("submitButton"); // HTML button
var textInput = document.getElementById("textInput"); // HTML text input

function addFunction(){
    var newItem = toDoList.createElement("p");
    newItem.innerText = textInput.value;
    document.toDoList.appendChild(newItem);
}

submitButton.addEventListener('click', addFunction);