开发者

Why is the rowIndex property of a jQuery returned element.parents("tr") row undefined?

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. Inste开发者_Python百科ad i have too:

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

to get an index.

Why is this?


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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜