I want my jquery to load a function when a button is clicked.
This works fine:
$(document).ready(function() {
$("#register").click(function() {
alert("button");
});
This one will show the test() function before the document loads:
$(document).ready(function() {
function test(param1, param2){
alert("param1: "+param1+" param2: "+param2);
}
$("#register").click(test("a","b"));
});
How can i fix this ?
readyhandler indicates that document has been loaded. Why do you think it's not?foo(bar())willbarfirst and pass the return value tofoo. Arguments are always evaluated first, that's how JavaScript works. There is no hidden magic for event handlers (which is a good thing).test()in this example before I click the button?