At the point you are calling your function, the rest of the page has not rendered and so the element is not in existence at that point. Try calling your function on window.onload maybe. Something like this:
You need to put the JavaScript at the end of the body tag.
It doesn’t find it because it’s not in the DOM yet!
You can also wrap it in the onload event handler like this:
window.onload = function() {
var refButton = document.getElementById( ‘btnButton’ );
refButton.onclick = function() {
alert( ‘I am clicked!’ );
}
}