FlamingPickle
FlamingPickle

Reputation: 189

Button onclick is fired when page loads

I am new to javascript and am trying to create a Chrome extension that get recenf nfl scores. I have added two buttons, but they are being clicked as soon as the extension loads. Why is this happening? I have added my EventListeners below.

document.getElementById("reg").addEventListener("click",inter("http://www.nfl.com/liveupdate/scorestrip/ss.xml"));
document.getElementById("post").addEventListener("click",inter("http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"));

Upvotes: 0

Views: 40

Answers (1)

Martin Konecny
Martin Konecny

Reputation: 59681

You need to wrap your inter function inside a function block:

document.getElementById("reg").addEventListener("click",function() {inter("http://www.nfl.com/liveupdate/scorestrip/ss.xml")});

Otherwise it is executed while the browser parses it.

Upvotes: 2

Related Questions