That's why bind() supports a 'data' argument:
$(document).ready(function(){
$(#earth).bind('click', { stuff: 'param1' }, myFunction);
$(#moon).bind('click', { stuff: 'param2' }, myFunction);
function myFunction(e){
alert( e.data.stuff );
};
});
see here:
function reuse(param) {
$(#moon).click(function(){
if(param == 1) {
alert(do something);
} else {
alert(Access Denied);
}
});
}
On Sat, Jun 13, 2009 at 6:53 PM, jwc droghe.digit...@gmail.com wrote:
Hi guys,
apologize for posting again the same topic. I
$(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
Interesting
someone has suggested it
$("#moon").click(myFunction("param"));
$("#earth").click(myFunction("param2"));
it involves less code, and it is probably faster because doesn't have condition statements that need to be executed.
Do you agree?
waseem sabjee ha scritto:
function
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;
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.
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
it is very fun! why?
2009/6/14 MorningZ morni...@gmail.com
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
What is that reply supposed to mean?
On Jun 13, 9:48 pm, John Bill hexudon...@gmail.com wrote:
it is very fun! why?
2009/6/14 MorningZ morni...@gmail.com
I thought it should have worked but it doesn't
You cannot pass params like that in a click event
instead of
9 matches
Mail list logo