Joel Birch wrote:
On 20/02/2007, at 12:17 AM, ad4m wrote:
Hi everybody!
I'm new to jquery and i've got some irritating problem. I want to assign an "on click" event to an <a> element. I'm using bind method and i'm getting the error like: "c[j].apply is not a function" in line 1002 in jquery script file. I have no idea what is the reason. Can you help me??

My code:
var dat = 'some text';
$().ready(function(){
   $('a.remote').bind('click', {'s':dat}, function(e){
         alert(e.data.s);
});
});

What i've noticed is when i use bind method witout passing to the callback funtion an object the bind method works ok. But I need to pass some additional data to the callback function...
Please let me now if someone now the explenation!!

regards,
Adam

Hi Adam,
From the API it seems that you are supposed to pass a data object as the second argument of bind ONLY IF the handler is a named reference to an existing function. Therefore, I assume you EITHER need to replace your anonymous function with a named reference of a function or just pass your additional data as a parameter of your anonymous function.
so either:

var dat = 'some text';
$().ready(function(){
    $('a.remote').bind('click', function(dat){
          alert(dat);
    });
});

OR:

function theHandler(e){
          alert(e.data.s);
}
var dat = 'some text';
$().ready(function(){
    $('a.remote').bind('click', {'s':dat}, theHandler);
});

Hope that works for what you want to do.
Joel.

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Hi Joel,
Thanx for your replay, it seems you were right! I should reed documentation more carefully... ;)

regards,
Adam
begin:vcard
note;quoted-printable:Serdecznie pozdrawiam,=0D=0A=
	Adam Ludwinski=0D=0A=
	[EMAIL PROTECTED]
	http://www.ludwinski.net
version:2.1
end:vcard

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to