tags:

views:

17

answers:

1

If i get a reference to an elements parent as follows:

function findParentRow(srcElement) {
    var curElement = srcElement;
    while (curElement && (curElement.tagName != "TR")) {
        curElement = curElement.parentElement;
    }
    return (curElement.tagName == 'TR' ? curElement : null);
}

I can:

var parentRow = findParentRow(someElement);
alert(parentRow.rowIndex);

and I will get a rowIndex alert. But if i:

var parentRow = $(chkBox).parents("tr");

I can

alert(parentRow);

and get an object but if i

alert(parentRow.rowIndex);

I get undefined. Instead i have too:

alert($(pRow).attr("rowIndex"));

to get an index.

Why is this?

+1  A: 

because parentRow is now a jQuery object... use .index() instead of rowIndex..

try .closest() also instead of .parents(),..

var parentRow = $(chkBox).closest("tr");
alert(parentRow.index());
Reigel
Just to add to your answer, the key concept for me was the idea of 'wrapped sets". Once i got that everything else fell into place. I fail to see why they arent mentioned in the jQuery.com "How it works" tutorial.
rism