Well, you set a global variable onclick
that translates into a global window
property object onclick
. This is basically the same thing that you should install it directly:
window.onclick = function() {
console.log("x = " + ++x);
};
And since you set the click event for the entire object window
, it will fire not only when the button is clicked, but also when you click on something inside your document (if the event is not stopped).
source
share