Thanks Kelly for the suggestion.... But using a return param in a function doesn't work completely because the function has a problem in another case that I didn't mentioned before. I have already solve with this sintax that allow me to use the same function once. $('#moon').click(function(){myFunction('param')}); $('#earth').click(function(){myFunction('param2')}); Thanks ;) Mirko, You were missing a small but significant point. The function you call must return a function. $('#moon').click(myFunction('param')); $('#earth').click(myFunction('param2')); function myFunction(param) { return function() { alert(param); }; } I suggest studying this pattern closely; it's one of the most powerful aspects of _javascript_. -Kelly On Jun 13, 9:07 am, 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 |
- [jQuery] anonymous function and code reusing Mirko Galassi
- [jQuery] Re: anonymous function and code reusing MorningZ
- [jQuery] Re: anonymous function and code reusing Kelly
- [jQuery] Re: anonymous function and code reusing Mirko
- [jQuery] Re: anonymous function and code reusing Ricardo
- [jQuery] anonymous function and code reusing jwc
- [jQuery] Re: anonymous function and code reusing waseem sabjee
- [jQuery] Re: anonymous function and code reusin... Mirko Galassi