I am new at JavaScript and I'm trying some events. The goal here is to click at some text and display a message. I have a p
element in my html like this:
<p id="tab">Click me</p>
At the .js file I tried this and nothing happened. The console yells me this:
"Uncaught TypeError: Cannot read property 'addEventListener' of null".
var demo=document.getElementById("tab");
demo.addEventListener("click", go);
function go(){
alert("Hey");
}
The code above resides in a separate .js file