albangt (16) [Avatar] Offline
#1
in chap4, toggle.html; I saw the following codes:

$(function(){
$('#vstar').toggle(
function(event) {
$(event.target).css('opacity',0.4);
},
function(event) {
$(event.target).css('opacity',1.0);
}
);
});

however, I didn't see any declaration of event, why function(event) can work well?
thanks
mraj (104) [Avatar] Offline
#2
Re: function(event) in chap4
> however, I didn't see any declaration of event, why
> function(event) can work well?

Hi albangt,
An Event object is passed as the first parameter to the listener function that you define (in jQuery 1.2). p. 104, section 4.2.3, talks about the first argument to the bind() command -- the same applies to the first argument of the other event-related convenience commands, such as toggle().

You may also want to look at http://docs.jquery.com/Events/toggle#fnfn2fn3.2Cfn4.2C...
Under "Arguments" it states:

fn Function
The function to execute.
function callback(eventObject) {
this; // dom element
}
bear.bibeault (675) [Avatar] Offline
#3
Re: function(event) in chap4
Yes, as mraj pointed out, you do not declare event -- jQuery passes it to your callback function automatically. As of jQuery 1.3, it's an instance of jQuery.Event which mimics the browser-supplied Event instance.
mraj (104) [Avatar] Offline
#4
Re: function(event) in chap4
Thanks for that note Bear, that helped clear up some confusion I had. I saw the "Event" object mentioned in the book (which apparently is a "clone of the native object as defined by the browser" with some "fixes"), but the online 1.3 docs talk about a "jQuery.Event" object. I'm glad they abandoned the "browser object with fixes" approach, and created something (which I assume is) cleaner.
bear.bibeault (675) [Avatar] Offline
#5
Re: function(event) in chap4
Exactly, prior, the Event object which was vastly different between the standard-compliant browsers and IE. Trying to fix it up helped, but still resulted in differences between the browsers. Now it's the same layout regardless.