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: http://docs.jquery.co
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()
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
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 re
$(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
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 wrote:
>
> Hi guys,
> apologize for posting again the same topic. I haven't found a s
What is that reply supposed to mean?
On Jun 13, 9:48 pm, John Bill wrote:
> it is very fun! why?
>
> 2009/6/14 MorningZ
>
>
>
> > "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(){
> >
it is very fun! why?
2009/6/14 MorningZ
>
> "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
"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
$(docum
9 matches
Mail list logo