There are at least three things wrong here:
- The event name for use with
addEventLisener()
is"click"
, not"onclick"
. - You should use the window
load
event OR theDOMContentLoaded
event, but not both. - Your click handler function isn't actually doing anything. Did you mean to call a function like
winPrize();
?
So, cleaning all of those issues, you would have this:
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("wheelContainer").addEventListener("click", function() { winPrize();
}, false);
});
You don't need the init()
function or the window load event handler at all since you can just install the event handler when the DOMContendLoaded
event fires.