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?
because
parentRowis now a jQuery object… use.index()instead ofrowIndex..try
.closest()also instead of.parents(),..