I'm having trouble referring to the event object in a jQuery function:
// Execute a function when an image with the arrow class is clicked
$('.arrow').bind('click',update_support);
// Function tries to refer to the calling image using $(this)
function update_support() {
alert( $(this).src );
}
// Result: an alert of 'undefined'
This code does work, but it passes the "this" object to the function explicitly, and I feel like there must be a better way:
$('.arrow').bind('click',update_support(this));
function update_support(obj) {
alert( obj.src );
}
// Result: an alert with the src of the clicked image
Edit to make my question clearer: Why should I have to give any arguments to the function explicitly? From jQuery docs at http://api.jquery.com/category/events/event-object: "The event object is guaranteed to be passed to the event handler." My question is: if I don't pass it explicitly, where is it? ;) ?