I have a form in my extension's popup with the code:
<button type="submit" id="update" class="btn btn-primary">Submit</button>
And then in the attached script, the following code:
document.addEventListener("DOMContentLoaded", function(event){
var button = document.getElementById("update");
button.addEventListener("click", test);
button.style.color="red";
});
function test(){
console.log("test");
}
The "button.style.color="red"" portion of the code works, so I know that the button was found successfully. However, I still receive this error upon load and when the button is clicked:
Uncaught TypeError: Cannot read property 'addEventListener' of null
How do I fix this :(