For example, if I have:
function example() {
alert("example");
}
Then why doesn't this work?
$("h2").click( example() );
Does it have to be defined inline?
For example, if I have:
function example() {
alert("example");
}
Then why doesn't this work?
$("h2").click( example() );
Does it have to be defined inline?
Nope, but the parens is making the function execute. Use this:
$("h2").click( example );
you want to just do $("h2").click(example);
- example should have no parenthesis
function example() {
alert("example");
}
$("h2").click(example);
just use
$("h2").click(example);
or
$("h2").click(function() { example(); });