Why is the jQuery on(“click”, “button”, …) running before the button is clicked?
I’m just learning jquery, and I’m running into behavior I don’t understand. I have:
The “hello” alert is appearing after the dom is loaded, as I would expect. However the “clicked” alert is firing as well, and does not subsequently fire when the button is pressed.
If you want it to be executed when clicking on the button, you would need to wrap it in a function: