- Jan 2, 2006
- 10,455
- 35
- 91
Code:
$(document).ready(function() {
var alertShit = function() {
alert("Shit.");
}
$("#alert").on("click", "button", alertShit() );
});
When I run this the function alertShit runs immediately on page load, NOT when the button is actually pressed. I thought func() with empty parenthesis was the correct way to call a function with no parameters?
Code:
$(document).ready(function() {
var alertShit = function() {
alert("Shit.");
}
$("#alert").on("click", "button", alertShit );
});
When I run *this* code and call the function with alertShit instead of alertShit(), it runs on button press.
What's going on?
Why is it that I have to call no-parameter functions with () everywhere else but in here I can't add the ()?