[jQuery] event handler mystery
Hi.
I'm relatively new to javascript in general, and to jQuery. And this
question may be more of a general javascript question, than a jQuery
question. Not sure.
I have an event handler for a click event that looks like this:
// this code works...
jInventoryView.prototype.rowDetailClicked = function(event, btn) {
if (btn.owner) {
var id = btn.owner.data.rowData[0].id;
btn.owner.grid.insertCustomRow(id, null);
}
};
It works okay as is. But what I'd like to do is assign btn.owner to a
local variable and then use it like this:
// this code fails for some unknown (to me) reason...
jInventoryView.prototype.rowDetailClicked = function(event, btn) {
var iv = btn.owner;
if (iv) {
var id = iv.data.rowData[0].id;
iv.grid.insertCustomRow(id, null);
}
};
This code, in fact, used to work before I upgraded from FF2 to FF3.
But now it's failing and Firebug is telling me that 'iv' is
undefined. I cannot understand how the first code snippet could work
while the second would fail?
The event is wired up in code using jQuery like this:
if (s.rowActions && s.rowActions.length > 0) {
var ra = s.rowActions[0];
$(rt).append(ra.text);
if (ra.clickFn) {
$(rt).click(function(event) {
ra.clickFn(event, ra);
});
}
}
Seems to me that the second version of my event handler (from above)
should work. For the life of me, I can't figure out why it doesn't.
Any help would be much appreciated.
Thanks,
Andy