Reputation: 1697
I have a table. Always multiple row in the table contain a attribute like selectrow="selectrow"
. For example 3rd and 4th row have selectrow="selectrow"
attribute. Now i want to find out the index of last row that have selectrow="selectrow"
attribute. I do not want to use each. I search for solution like this :
$("table > tbody > tr[selectrow='selectrow']:last-child").index();
This is html:
<table>
<tbody>
<tr >
</tr>
<tr>
</tr>
<tr selectrow="selectrow">
</tr>
<tr selectrow="selectrow">
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
</table>
In this example i want to get 4.
Upvotes: 0
Views: 53
Reputation: 28513
Try this : use :last
which will give you last of the matched selection. :last-child
will select the last child of table and try to match the other selection criteria (selectrow='selectrow'
in your case) and when match not found then it will retrun -1.
$("table > tbody > tr[selectrow='selectrow']:last").index();
More Information on
:last
:last-child
Upvotes: 4
Reputation: 3015
Try this
$("table > tbody > tr[selectrow='selectrow']").last();
it will return the object of last tr
.
Upvotes: 1