javascript - jQuery - How to select last column of all rows in a table? -
assuming have html table follows (with appropriate tr, td tags):
a1 | b1 | c1 a2 | b2 | c2 a3 | b3 | c3 a4 | b4 | c4 <table border="1"> <tr> <td>a1</td> <td>b1</td> <td>c1</td> </tr> <tr> <td>a2</td> <td>b2</td> <td>c2</td> </tr> <tr> <td>a3</td> <td>b3</td> <td>c3</td> </tr> <tr> <td>a4</td> <td>b4</td> <td>c4</td> </tr> </table>
i'm trying select c* rows perform action on them.
using $('td:last')
selector selects last td tag, i.e., c4.
i tried $('tr > td:last')
didn't work. correct selector in case?
:last
jquery selector, select very last element of type. you're looking :last-child
.
similarly, td:first-child
first cell, while :first
gets first element of type.
here's fiddle @ 4 examples.
Comments
Post a Comment