PreventDefault isn’t working. The alert doesn’t appear.
My code:
<!DOCTYPE html>
<html>
<head>
<style>
* {
text-align: center;
font-family: Arial;
}
#btn {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Tests</h1>
<form>
<div><input id="info" type="text" /></div>
<div><button id="btn" type="submit">Enter</button></div>
</form>
<script>
function respond(event) {
event.preventDefault();
alert("Hi there!");
return false;
}
document.getElementById("btn").addEventListener("submit", respond);
</script>
</body>
</html>
All I’m trying to do is stop the default refreshing and get the alert to show up. This is super basic, but it’s not working and I can’t figure out why not.