Can someone explain why this button does not work? An error in my console indicates that it var button = document.getElementById('next');returns null.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<script>
...
</script>
</head>
<body>
<button id="next">Say hi</button>
</body>
</html>
JavaScript:
var button = document.getElementById('next');
function sayHi(){
alert('Hi there');
}
button.addEventListener('click',sayHi,false);
thanks for the help
source
share