$(document).ready(function(){
    $("#moon").click(function() { myFunction("param"); });
    $("#earth").click(function() { myFunction("param2"); });
});
It works perfectly!
Thanks

MorningZ ha scritto:
"I thought it should have worked but it doesn't"

You cannot pass params like that in a click event

instead of

$(document).ready(function(){
  $("#moon").click(myFunction("param"));
  $("#earth").click(myFunction("param2"));

  function myFunction(param){
    alert(param);
  }
});


use

$(document).ready(function(){
    $("#moon").click(function() { myFunction("param"); });
    $("#earth").click(function() { myFunction("param2"); });
});

function myFunction(param){
    alert(param);
}


On Jun 13, 12:07 pm, Mirko Galassi <mirko.gala...@ymail.com> wrote:
  
Hi guys, apologize for posting again the same topic. I haven't found a solution yet for my simple problem. I have a simple function that works when a link is clicked $(document).ready(function(){ $("#moon").click(function(){ alert("do something"); }); }); I need to reuse that function passing a parameter so I modified the function like that $(document).ready(function(){ $("#moon").click(myFunction("param")); $("#earth").click(myFunction("param2")); function myFunction(param){ alert(param); } }); I thought it should have worked but it doesn't. In fact, when the page has loaded even without clicking the first and second istructions are executed: $("#moon").click(myFunction("param")); $("#earth").click(myFunction("param2")); whereas with the following case $("#moon").click(function(){ alert("do something"); }); the function need to be activate by a click any idea? Thanks a lot c
    

  

Reply via email to