Why doesn't this work, I want it to show me "sure to proceed?" When I click the button to which the ".collect" class is attached.
const button = document.querySelector(".collect");
button.addEventListener("click", function() {
alert("Sure to proceed?");
});
<button type="submit" class="collect">PROCESS</button>
Executing the JavaScript after the target element solves the problem, refer to the post anchored to @David 's comment. Thanks.