passing objects in jquery click event -
i have wrong , not working.
i'm trying call 1 shared function alert data passed called 2 different click events |i underfined in alert. why underfined?
var myf = function(){ alert('a click ' + this.model + ' ' + this.year); // meant alert properties of object passed alert(this.id); // meant alert id of click called }; var mycar = new object(); mycar.make = "ford"; mycar.model = "mustang"; mycar.year = 1969; var mycar2 = mycar; mycar2.make = "vw"; mycar2.model = "golf"; mycar2.year = 2000; $('.feature1').click(mycar,myf); $('.feature2').click(mycar2,myf);
to access data in event handler, must use event.data
:
var myf = function(e){ alert('a click ' + e.data.model + ' ' + e.data.year); alert(this.id); };
moreover, property contains id called id
, not id
. , have typo mycar2 = mycar
instead of mycar2 = mycar
.
Comments
Post a Comment